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:
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
2010-06-02 07:17:23
yes Thanks a lot
faisal
2010-06-02 07:35:38
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
2010-06-02 07:39:16
please see my edited jQuery.. and if you are happy, please don't forget to accept answer.. ;)
Reigel
2010-06-02 07:52:54
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
2010-06-02 07:58:36
`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
2010-06-02 08:07:00
also, var data = {'id': this.value } relates directly to the parameters that the php /.net 'controller/page' would be expecting.
jim
2010-06-02 08:11:23
:) now get thanks
faisal
2010-06-02 08:12:38