Retrieving the Selected value dynamically in JQuery
- by Chakradhar
i have this html, this is generated dynamically based on question number
<fieldset id="selectfield">
<label class="select">What ur is Profession?
</label>
<br>
<div class="ui-select"><a href="#" role="button" id="72+_select-button" aria-haspopup="true" aria-owns="72+_select-menu" data-theme="c" class="ui-btn ui-btn-icon-right ui-btn-corner-all ui-shadow ui-btn-hover-c ui-btn-up-c"><span class="ui-btn-inner ui-btn-corner-all" aria-hidden="true"><span class="ui-btn-text">Business</span><span class="ui-icon ui-icon-arrow-d ui-icon-shadow"></span></span></a>
<select name="selectedObjects" id="72+_select" data-native-menu="false" tabindex="-1">
<option value="-1">--Select--</option>
<option value="769">Salaried</option>
<option selected="selected" value="770">Business</option>
<option value="771">Self Emp</option>
</select></div>
</fieldset>
click button is
<div data-theme="c" class="ui-btn ui-btn-corner-all ui-shadow ui-btn-hover-c ui-btn-up-c" aria-disabled="false"><span class="ui-btn-inner ui-btn-corner-all" aria-hidden="true"><span class="ui-btn-text">Next</span></span>
<input type="submit" id="72+_b" onclick="return SaveDropDown(this);" value="Next" class="ui-btn-hidden" aria-disabled="false">
</div>
i have written this JS in SaveDropDown(this)
function SaveDropDown(button) {
var fieldsetName = getQuestionName(button.id)+'+_select';
var select = $(fieldsetName +"option:selected").val();
return false;
}
the questionname function is
function getQuestionName(buttonid) {
var splitstr = buttonid.split('+');
var fieldsetName = '#' + splitstr[0];
return fieldsetName;
}
but its returning the undefined how do i retrieve the select value dynamically.
any help is appreciated.