Note that there are some explanatory texts on larger screens.

plurals
  1. POget the selected value of selectmenu jquery
    text
    copied!<p>I have a form with couple of drodowns that are styles using selectmenu. These drodowns are hidden initially. On certain conditions it will be displayed. So i need to check if the dropdowns are displayed, the user should select a value from that and then only allow him to submit the form. If the user is not selecting any value, error should be displayed and the form should not be submitted. </p> <p>JS file for selectmenu</p> <pre><code>if ($.fn.selectmenu) { $('select.dd-select').selectmenu({ style:'dropdown', maxHeight: 300, transferClasses: true }); } </code></pre> <p>JS file for validation</p> <pre><code>$('#submitbutton').click(function(){ var returnValue = true; $('#form1 .required').filter(':visible').each(function () { inputVal = $(".dd-default option:selected").val(); alert(inputVal); -- displaying null var input = $(this);alert(input.val()); -- displaying null input.next('ul.innererrormessages').remove(); input.removeClass('required'); if (!input.val()) { input.addClass('required'); var $msg = input.attr('title'); input.after('&lt;ul class="innererrormessages"&gt;&lt;li&gt;'+$msg+'&lt;/li&gt;&lt;/ul&gt;'); --error message not shown returnValue = false; } }); }); $('#form1 .required').change(function () { var input = $(this); input.next('ul.innererrormessages').remove(); input.removeClass('required'); alert(input.val());-- displays the value if (!input.val()) { input.addClass('required'); var $msg = input.attr('title'); input.after('&lt;ul class="innererrormessages"&gt;&lt;li&gt;'+$msg+'&lt;/li&gt;&lt;/ul&gt;');-- the error message is also displayed properly } }); </code></pre> <p>HTML</p> <pre><code>&lt;select id="dd1" name="dd1" class="required dd-select" title="Please select to continue."&gt; &lt;option value=""&gt; --&lt;/option&gt; &lt;%= List %&gt; &lt;/select&gt; </code></pre> <p>In the above code, if no values are selected, its highlighting but not displaying the error. The error it should take from the title attribute of the select. On change of the value, its alerting the new value. But on submit again the value is displayed as null. I dont know how to create a fiddle for this with selectmenu. If I create a fiddle only with the dropdown validation, it works fine. I think when its selectmenu, do we have any separate way to get the selected value? Can somebody please tell me what I am doing wrong and guide me on this? Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload