Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update 2 select boxes with same option using jquery mobile

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
0
0
US
Using jquery/jqm I need to add an option to 2 selectboxes. I can get one to update but not the other. How do I get the other one to update. Notice the S in the names/id's Whichever .append is listed 2nd is the one that is updated.

html:

<input type="button" name="Goal_WeightVar" id="Goal_WeightVar" value="doit">
<br>
<select name="grouplist" id="grouplist">
<option value="choose">Choose a Group</option>
<option value="#groupid#">option1</option>
</select>
<select name="groupslist" id="groupslist">
<option value="choose">Choose a Group</option>
<option value="#groupid#">option1</option>
</select>
script:

$('#Goal_WeightVar').live('click', function() {
var newgroupcode = $('<option value="11">11<option>');
$('#groupslist').append(newgroupcode).trigger("create");
$('#grouplist').append(newgroupcode).trigger("create");
$('#groupslist').selectmenu();
$('#groupslist').selectmenu('refresh');
$('#grouplist').selectmenu();
$('#grouplist').selectmenu('refresh');
});

JSFIDDLE
Chris Scott
 
Found the answer:
must use clone() to clone newgroupcode..

$('#Goal_WeightVar').live('click', function() {
var newgroupcode = $('<option value="11">11<option>');
$('#groupslist').append(newgroupcode).trigger("create");
$('#grouplist').append(newgroupcode.clone()).trigger("create");
$('#groupslist').selectmenu();
$('#groupslist').selectmenu('refresh');
$('#grouplist').selectmenu();
$('#grouplist').selectmenu('refresh');
});


Chris Scott
 
you need to add a 'true' argument to clone also the inner elements and the events attached to the cloned object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top