0

How to get value from select box dynamically without loading page and use that value in if condition ?

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
Vin_fugen
  • 581
  • 3
  • 19
  • 38

3 Answers3

0

"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 ifs as you like...

Further reading: jQuery's .val() method

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
0

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
Community
  • 1
  • 1
donlaur
  • 1,269
  • 1
  • 12
  • 21
0

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()); 
});
Swarne27
  • 5,521
  • 7
  • 26
  • 41