I can able to get the selected option value in onchange event. But, when clicking the ok button in the same page , I can’t get the value selected. Please help me..
Code is as follows:
<select id ="userstoassign">
<option value="s1">S1</option>
<option value="s2" selected="selected">S2</option>
<option value="s3">S3</option>
</select>
<input type="button" name="ok" id="ok" value="ok"/>
$("#ok").live('click', function(){
var username= $("#userstoassign option:selected").val();
alert(username);
});
Note: In onchange event, I can get the selected value. Temp fix is I’m getting that value in onchange event in a variable and will use it in onclick event. Even in onchange event I’m getting default value if I use the code “$(“#userstoassign option:selected”).val();”
$('#userstoassign').live('change',function(){ selectedUser=this.value;
alert(selectedUser);
});
Reason being I’m including my jsp in another jsp which is creating this issue. But, if I create select box dynamically, then I’m not getting that issue. But, stil couldn’t find why this bug is occuring.
In this common.jsp, I’m using select box, which is creating this issue. I removed select box from this jsp and creating it dynamically in the js.