Widget:ArithmeticWorkout

This is a test widget: the goal is to add a drop down menu so an arbitrary level can be choosen for the arithmetic workout flash simulation. This should eliminate the needs to edit the wiki page for young children or users that are not familiar with wiki syntax. /*<![CDATA[*/ $(function { var dn = '';  var dId = '#'+ dn;  var dd = 'dropDown';  var ddId = '#' + dd;

function createDropDown(dId, dd){ $(dId).append($(' ').attr('id',dd)                                         .append($(' -Select a level- '))                                         .append($(' Beginner '))                                         .append($(' Level 4 '))                                         .append($(' Intermediate '))                                         .append($(' Level 6 '))                                         .append($(' Level 7 '))                                         .append($(' Level 8 '))                                         .append($(' Advanced '))                                         .append($(' Level 10 '))                                         .append($(' Level 11 '))                                         .append($(' Level 12 '))                    ); }; var changeButton; if (wgUserName === null) { changeButton = ' You must login to  change the level'; $(dId).append(changeButton);

} else { createDropDown(dId,dd); } $(ddId).click(function  {    // disable the buttons    $(ddId).attr('disabled', 'true');    var mylevel = $(ddId).val;    // load the wikitext and an edit token    var weAPI = wgServer + '/api.php';    $.ajax({ type: 'POST', url: weAPI, data: { action: 'query', prop: 'info|revisions', intoken: 'edit', titles: wgPageName, rvprop: 'content', format: 'json' },     error: function(hdr, stat, err) { alert("Unable to fetch data page!\n" + stat); },     success: function (d) { for (var pg in d.query.pages) { var page = d.query.pages[pg]; var token = page.edittoken; var wikitext = page.revisions[0]['*']; }       $.ajax({          type: 'POST',          url: weAPI,          data: {            action: 'edit',            title: wgPageName,            summary: 'Update level to ' + mylevel,            text: wikitext.replace(/levelA=[0-9]+/, 'levelA=' + mylevel),            token: token,            format: 'json'          },          error: function(hdr, stat, err) {            alert("Unable to save data!\n" + stat);          },          success: function (d) {            // lazy way to redraw, reset            window.location = wgServer + '/' + wgPageName;          }        }); }   });  });  }); /* ]]> */