javascript - How to retain the dropdown selection after a dynamic creation of a table- Jquery -
i have dropdown created dynamically within function.
function userlist() { $('#user-list').append('<select id="users-type-customers">'+ '<option value="some">some users</option>'+ '<option value="allcustomer">all users</option>></select>'); }
and have function handle drop downwards on alter event:
&('#users-type-customers').on("change", function(){ dropdownselect = $('#users-type-customers :selected').val(); switch (dropdownselect) { case "allcustomer": { typeval = "all"; break; } case "some": { typeval = "some"; break; } } $.ajax({ type: 'get', data: {"item": typeval}, success: function (model) { this.userlist() //calling userlist function } }); })
so happens when select all users
option, gives me teh necessary info on success, when phone call userlist()
, appends dropdown table , displays default value ( beingness 'some users' in case), seems obvious. im not sure how phone call function while taking care maintain selection intact , not restore default value. ideas?? thanks!
use:
function userlist(typeval) { $('#user-list').append('<select id="users-type-customers">'+ '<option value="some">some users</option>'+ '<option value="allcustomer">all users</option>></select>'); $('#users-type-customers').val(typeval); }
javascript jquery
No comments:
Post a Comment