I want to have an jquery ui autocomplete to get the data from certain mysql tables. So if the html select is from email, it will send param to the php to get data from email table. if handphone it will send the param so the php select different table.
However, the script seems to send only the 1st value of the html select. How to fix this?
<script>
$(function(){
$("#birds").autocomplete({source:"get.data.php?type="+$('#type').val()+"&"});
});
</script>
</head>
<body>
<div class="ui-widget">
<select id="type"><option value="b2">Email</option><option value="b3">Handphone</option></select>
<label for="birds">Birds: </label>
<input id="birds" size="50" />
</div>
I've tried this and it also failed. The script only send the 1st value of the select, not the second.
<script>
$(function(){
type=$('#type').val();
$('#type').change(function(){type=$('#type').val();});
$("#birds").autocomplete({source:"get.data.php?type="+$('#type').val()+"&"});
});
</script>
</head>
<body>
<div class="ui-widget">
<select id="type"><option value="b2">Email</option><option value="b3">Handphone</option></select>
<label for="birds">Birds: </label>
<input id="birds" size="50" />
</div>
Can anyone help? Thank you.
============================================
ANSWERED by Rajesh as below...
<script>
$(function(){
$('#type').change(function(){$("#birds").autocomplete( "option", "source", "get.data.php?type="+this.value+"&");});
$("#birds").autocomplete({source:"get.data.php?type="+$("#type option:selected").val()+"&"});
});
</script>