0

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>

2 Answers 2

1

try something like this

            $('#type').change(function(){
                $("#birds").autocomplete( "option", "source", "get.data.php?type="+this.value+"&");
            });
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @rajesh. This works perfectly. I'll edit the answer in my question above.
0

Try $("#type option:selected").val() to get the selected value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.