How to get VALUE from FORM without Submitting it?

Solution 1:

I think, if you dont want page to be refreshed when user selects value from your drop down list, then you can use ajax. AJAX is used for this purpose. if you google, then you will find lots of tutorials related to AJAX.

Solution 2:

If you don't want to submit the form, use JavaScript to get the element. Or you can also use jquery to access the value. Make sure you put id = "something" and retrieve it using $('#something').val();

if you want to use JavaScript,

<select name="house_model" id="model">
    <option value="">------</option>
    <option value="<?php echo $model1;?>">Model 1</option>
    <option value="<?php echo $model2;?>">Model 2</option>
    <option value="<?php echo $model3;?>">Model 3</option>
</select>

<script type="text/javascript">
    var model= document.getElementById('model');
    alert("You entered: " + model);
</script>

AJAX codes here

 $("#model").live("change", function () {
     alert("You choose " + $('#model').val());
 });

Solution 3:

IF you don't want to submit your form, you can get element using AJAX/jQuery.

<form method="GET" action="foo.php" onChange="getHouseModel">
  <select name="house_model" id="house_model">
    <option value="">------</option>
    <option value="<?php echo $model1;?>">Model 1</option>
    <option value="<?php echo $model2;?>">Model 2</option>
    <option value="<?php echo $model3;?>">Model 3</option>
  </select>
</form>

<script type='text/javascript'>
   function getHouseModel(){
      var model=$('#house_model').val();
      alert(model);
}
</script>

or you can write jquery like this. so you dont have to call function in tag

<script type="text/javascript">
    $('#house_model').select(function() {
       var model=$('#house_model').val();
      alert(model);
     });
</script>