I should have expounded more on the rest of it, but I had to run to a meeting. My apologies. :(
On Mar 31, 11:21 am, LinkGuru <i...@legalanalytics.co.uk> wrote: > Apologies to Rob (I had only tried his 'add the id attribute to > the select tag' suggestion), I now find that if I write p_viewSelector= > $("select[name='dllViewSelector'] option:selected").text(); it works > fine. Thanks Rob (and also Ricardo). > > On Mar 31, 3:53 pm, Ricardo <ricardob...@gmail.com> wrote: > > > The val() method returns the selected option for the element: > > > $('[name=dllViewSelector]').val() > > > 'selectedIndex' is a property of the <select> node. When you call $ > > ('#dllViewSelector') (ignoring the fact that this selector is wrong) > > you get a jQuery object with a reference to the element, not the > > element itself. You can access it like in an array: > > $("#dllViewSelector")[0].selectedIndex; > > > On Mar 31, 7:51 am, LinkGuru <i...@legalanalytics.co.uk> wrote: > > > > Hi, Can anyone help with the following? With JQuery, I can't > > > successfully grab the selected value from a drop-down. The alert just > > > shows an empty message. At least it is not showing undefined (as it > > > was for my other attempts - you can see what these were from the > > > commented out code), but I would expect it to display one of the > > > values One-way, Reciprocal or Other. Perhaps I have to do some > > > conversion on the result. Your contributions to this post will be > > > greatly appreciated. > > > > In my HTML I have: > > > > <select name="dllViewSelector" > > > onchange="showSelectedView(this, allViews, > > > allSections,4,10)"> > > > > <option id="oneway_4" value="one" selected="selected">One- > > > way</option> > > > <option id="recip_4" value="two">Reciprocal</option> > > > <option id="other_4" value="three">Other</option> > > > </select> > > > . > > > . > > > . > > > <span id="Add_0" class="actionOptAdd"> <input type="button" > > > name="btnOk_AddToProject_0" class="button-click-grey" value="Add to > > > Project" /></span> > > > . > > > . > > > . > > > And in my JQuery I have .... > > > > $(".actionOptAdd").bind("click", > > > function() > > > { > > > p_viewSelector=$("#dllViewSelector > > > option:selected").text(); > > > alert(p_viewSelector); > > > // Also get blank message for: > > > // p_viewSelector=$("#dllViewSelector > > > option:selected",this).text > > > (); > > > // (Also tried - getting undefined as a result) > > > // > > > p_viewSelector=$("#dllViewSelector").selectedIndex; > > > // > > > p_viewSelector=$("#dllViewSelector").attr("selectedIndex");