i have been reviewing lot of pages , can't seem figure out why isn't working.
in html page using php dynamically create dropdown box on page this:
$sel = '<select "id"="userphones">'; foreach ($user_phones $single_phone) { $phoneid = $single_phone['id']; $phonenum = $single_phone['phone_num']; if($single_phone['isdefault']=='1') { $sel.="<option id=".$phoneid." selected='selected'>".$phonenum."</option>"; } else { $sel.="<option id=".$phoneid.">".$phonenum."</option>"; } } $sel .='</select>'; echo $sel;
i see dropdown appear on page without problem , looks working. later try use jquery @ value of dropdown act on doing this:
phone_num = $('#userphones :selected').val(); alert(phone_num);
for reason whenever try @ value getting alert of "undefined" , not value of dropdown. sure being set because have looked @ source of page , have checked firebug elements exist on page. have tried using id of dropdown , val(), have tried using text() cannot seem grab anything. can please tell me on earth going on here? have been racking brains while now.
the id
field in select element should not have quotes around it. it's not valid markup , jquery not find id.
Comments
Post a Comment