2levelsabove Posted March 29, 2010 Share Posted March 29, 2010 Hello, I have a simple combobox : <select id="selwebsiteid"> <option value="0">Select a profile</option> <option value="1">Test 1</option> <option value="0">Test 2</option> </select> and when i do jQuery('#selwebsiteid :selected').text() to get the selected text and it comes back with "Select a profile" appended at the begining of any option i select. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/196905-jquery-selected-is-returning-an-array/ Share on other sites More sharing options...
Zane Posted March 29, 2010 Share Posted March 29, 2010 I'm not too clear on what you're asking, but you could try using the val() function instead of text(). ........lected').text() to ....... ........lected').val() to ....... Quote Link to comment https://forums.phpfreaks.com/topic/196905-jquery-selected-is-returning-an-array/#findComment-1033723 Share on other sites More sharing options...
2levelsabove Posted March 29, 2010 Author Share Posted March 29, 2010 I am actually trying to get the text label instead of the value that was selected. So in my example, i am trying to get the "test1" and "Test2" Quote Link to comment https://forums.phpfreaks.com/topic/196905-jquery-selected-is-returning-an-array/#findComment-1033725 Share on other sites More sharing options...
Zane Posted March 29, 2010 Share Posted March 29, 2010 Are you sure your not just prepending "Select a profile" onto the variable somewhere. From the code you've shown us,.. I see nothing wrong with it. Nothing near what you're explaining Quote Link to comment https://forums.phpfreaks.com/topic/196905-jquery-selected-is-returning-an-array/#findComment-1033732 Share on other sites More sharing options...
RichardRotterdam Posted March 30, 2010 Share Posted March 30, 2010 You're selecting the select element text instead of the option element. try this: <script type="text/javascript"> jQuery (document).ready (function (){ jQuery ('#selwebsiteid').change (function () { var selectedText = jQuery('#selwebsiteid option:selected').text(); console.log(selectedText); }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/196905-jquery-selected-is-returning-an-array/#findComment-1034046 Share on other sites More sharing options...
2levelsabove Posted March 30, 2010 Author Share Posted March 30, 2010 Thank you so much for the reply. That did not work also. I am also positive that my DOM gets corrupt somewhere. Not sure where. No matter what I do, I am getting the "Select a profile" prepended to the option I select. Quote Link to comment https://forums.phpfreaks.com/topic/196905-jquery-selected-is-returning-an-array/#findComment-1034129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.