thugsr Posted October 15, 2013 Share Posted October 15, 2013 Hi, I have problem with this line var value = $("#opstina option:selected").val(); , but only in chrome i get that value is undefined. In FireFox, and IE, works fine, only in chrome i get this warning. Does someone know why? My whole jquery code is if ($("#drzava option:selected").length) { $("select#opstina").attr("disabled","disabled"); $("select#opstina").html("<option>wait...</option>"); var id = $("select#drzava option:selected").attr('value'); $.post("select_opstina.php", {id:id}, function(data){ $("select#opstina").removeAttr("disabled"); alert( "html koji bi trebao biti upisan u select:\n\n" + data ); $("select#opstina").html(data); }); if ($("#opstina option:selected").length) { alert('Došao sam pred petlju'); var value = $("#opstina option:selected").val();//this is line that is problem alert(value); var sel = $("#opstina").val(); // this do the same if (sel!=0) { alert('Ušao sam u petlju, i selektovano polje za opštinu je' + sel ); $("select#mesto").attr("disabled","disabled"); $("select#mesto").html("<option>wait...</option>"); var id= $("select#opstina option:selected").attr('value'); alert(id); $.post("select_mesto.php", {id:id}, function(data){ alert("html koji bi trebao biti upisan u select:\n\n" + data ); $("select#mesto").removeAttr("disabled"); $("select#mesto").html(data); }); } } } } Link to comment https://forums.phpfreaks.com/topic/282979-jquery-select-selected-value-undefined/ Share on other sites More sharing options...
codefossa Posted October 15, 2013 Share Posted October 15, 2013 Just select the select, rather than the option. Tested working in Firefox & Chrome: http://jsfiddle.net/XR6DT/ I'm a Linux user, so I can't really test IE, but it should work as well. Link to comment https://forums.phpfreaks.com/topic/282979-jquery-select-selected-value-undefined/#findComment-1453974 Share on other sites More sharing options...
thugsr Posted October 15, 2013 Author Share Posted October 15, 2013 But i need selected value, not change. This should be part with pre-selected value. Link to comment https://forums.phpfreaks.com/topic/282979-jquery-select-selected-value-undefined/#findComment-1453976 Share on other sites More sharing options...
codefossa Posted October 15, 2013 Share Posted October 15, 2013 I showed getting the value on change. That way it had a trigger you could play with. The value is grabbed: $(this).val()And $(this) points to $("select") in my example. I only have one select tag, so it's fine to use as a trigger. Although, it's pointing directly to the one that was triggered. If there were more select tags, it would still point to the one you changed in that example. You were pointing to the option tag, when you can simply call the value of the select element. Link to comment https://forums.phpfreaks.com/topic/282979-jquery-select-selected-value-undefined/#findComment-1454014 Share on other sites More sharing options...
thugsr Posted October 21, 2013 Author Share Posted October 21, 2013 My trigger in this case should be selected value. For first two selects i get the value, only for third i cant.. Link to comment https://forums.phpfreaks.com/topic/282979-jquery-select-selected-value-undefined/#findComment-1454717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.