tags:

views:

17

answers:

2

Hi all,,, I am trying to do a small thing, any 1 help me, I really appricciate... I have a drop down menu,I want when I select the value, it will call the related data, which I am access with php+mysql, I dont want to jump to other page and show

A: 

http://api.jquery.com/category/ajax/

jAndy
A: 

html

<select id="select1" size="1">
   <option value="1">value 1</option>
</select> 

jQuery

$(document).ready(function(){
  $('#select1').change(function(){
   var url;
   if (this.value == 1) {
       url = 'sample1.php'
   } else if (this.value == 2) {
       url = 'sample2.php'
   } else {
       url = 'sample3.php'
   }
   var data = {'id': this.value }
   $.ajax({
      method: 'get',
      data: data,
      url: url,
      success: function(result){
         alert(result);
      }
   });
  });
})

php sample.php

<?php 

   if ($_GET['id']) {
      // do some MySql stuff....
      echo 'some result';
   }
?>

something like that... ;)

Reigel
yes Thanks a lot
faisal
1 more thing, wht If I want to call differnt pages, like <select id="select1" size="1"> <option value="1">value 1</option> <option value="2">value 2</option></select> when value 1 select, call sample1.phpand when value 2 select, hide sample1.php and show sample2.php
faisal
please see my edited jQuery.. and if you are happy, please don't forget to accept answer.. ;)
Reigel
thank u soo much again, if u have time, I just want to ask u, wht is the use of this... " var data = {'id': this.value } "can u please tell me ............ again thank uuuuuuuuuuuuu :)
faisal
`this` represents the `select` in our case... so `this.value` is the value of the `select`... the `value` changes depending on what option was selected... hope I was clear.. I'm really not good on explaining.. ;)
Reigel
also, var data = {'id': this.value } relates directly to the parameters that the php /.net 'controller/page' would be expecting.
jim
:) now get thanks
faisal