How to get value from select box dynamically without loading page and use that value in if condition ?
-
1The select box doesn't exist till the page is loaded. – Asad Saeeduddin Jan 09 '13 at 08:10
-
server side if or client side if ? – Arun Killu Jan 09 '13 at 08:14
3 Answers
"without loading page"
I'm going to guess that you mean "without submitting the form" and reloading the page, since you obviously can't get the value of a control on a page without loading that page.
Just do something like this:
var val = $("#idOfSelectHere").val();
if (val === "something" || val === "something else") {
// do something
} else if (val === "whatever" && someOtherCondition) {
// do whatever
}
Obviously you can add as many conditions and else if
s as you like...
Further reading: jQuery's .val()
method

- 147,572
- 30
- 200
- 241
You haven't provided code but a previous question should provide good answers.
Get selected value in dropdown list using JavaScript?
When you say without loading page, I assume you mean without hitting submit and reloading the page.
You can also use jquery to get your result... assuming the pulldown is num states.
$("#numstates").val() //the value of the selected option
To get the default selected option of selectbox use,
var selected = $("#selectboxId").find(":selected").text();
You can use following way to get the user selected value,
$("#selectboxId").change(function () {
alert($(this).val());
});

- 5,521
- 7
- 26
- 41