jquery - In javascript get the value of dropdown -
i populating values in drop down database. every text have values. want select values using javascript..
my code
<%= html.dropdownlist("role", viewdata["role"] selectlist,"select" , new {onchange = "javascript:ddlrolechanged();", id="ddlroles", @class = "dropdownstyle2"})%>
javascript code:
<script type="text/jscript"> $(document).ready(function () { var tempddval = '<%= session["function"] %>'; $("#ddlroles option:contains(" + tempddval + ")").attr('selected', 'selected'); }); function ddlrolechanged() { debugger; var selectvalue = document.getelementbyid('#ddlroles'); var selectedvalue = $('#ddlroles').val(); window.location = '/home?func=' + selectedvalue.valueof(); }; </script>
but selectedvalue
showing text values.. how take that?
you want selected item #ddlroles
. try this:
var selectedvalue = $('#ddlroles option:selected').val(); window.location = '/home?func=' + selectedvalue;
Comments
Post a Comment