Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a select box of html and i added some option on it, when i select option from this select box. the whole page is being refresh. i want to display selected option of select box using jquery how can i do selected text in select box. below is by code

XML
<select id="SelectItem" onchange="Settings();">
       <option value="-1">Select</option>
       <option value="0">Supervisors</option>
       <option value="1">Solid Surface Company</option>
       <option value="2">Comment Reason</option>
   </select>

<script type="text/javascript">
function Settings() {
var x = $("#SelectItem").val();
var y = $("#SelectItem option:selected").text();
var url = "";
if (x == "-1") {
url = "Home/Settings";
}
if (x == "0") {
url = "Supervisors/Index";
}
if (x == "1") {
url = "SSCompany/Index";
}
if (x == "2") {
url = "CommentsReason/Index";
}
var OriginalUrl = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : '') + "/" + url;
window.location.replace(OriginalUrl);
};

</script>
Posted
Updated 25-Aug-14 0:12am
v2
Comments
Ranjeet Patel 25-Aug-14 5:12am    
Not being clear can you update your question with the code sample
Kumarbs 25-Aug-14 8:38am    
What is your query?
Ranjeet Patel 26-Aug-14 3:38am    
in your question many things are confusing me.
1) the page should refresh on the selecting the select Item or not.?
2) the page is being refreshed because you are writing the below line
var x = $("#SelectItem option:selected").val();
In my view replace the line with

var x = $("#SelectItem").val();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900