Reputation: 4078
I am using a autocomplete
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
And below i have two pages index.php
and ajx_page.php
<form name="send_coup_ajx_form" id="send_coup_ajx_form" method="post">
<select name="member_type" id="member_type">
<option value="customer_type">Customer</option>
<option value="BPartner_type">Business Partner</option>
</select>
<input type="text" name="sel_rad" id="resultant_text" />
<input type="submit" name="submit" value="go" />
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#resultant_text").autocomplete("ajx_page.php", {
width: 260,
matchContains: true,
//mustMatch: true,
//minChars: 0,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false
});
});
</script>
And below code for
<?php
$select_type = $_GET['member_type'];
$type = $_GET['sel_rad'];
?>
when i type in the textbox, it gives me an error as
Notice: Undefined index: member_type in ajx_page.php on line 2
That means member_type
is not going in that page..
And when i comment all this code and put the below code in ajx_page.php
<?php
echo "Name1\n";
echo "Name2\n";
echo "Name3\n"
?>
It displaying autocomplete feature list. but when i want to get the value of that object member_type
it is saying an error..
so how do i pass additional values using this autocomplete plugin
I have added an Image to overwriting problem to @veeTrain
Upvotes: 0
Views: 687
Reputation: 2915
I'm not sure if the autocomplete plugin is intended to handle this type of scenario or not.
However, if you want to manually pass these values into your php script, then it would be pretty simple (at least in this scenario where you are only trying to send two fields in).
var memberType = $("#member_type>option:selected").val();
var selRad = $("#resultant_text").val();
$("#resultant_text").autocomplete("ajx_page.php?member_type="+memberType+"&sel_rad="+selRad, {
//...
But this probably isn't the answer answer you're looking for.
Update: I'm glad that syntax for sending the values is working for you.
It looks like you have overlapping ids being printed out -- is that what you mean by 'bold'? Apparently you aren't using the correct delimiter for creating a second auto-complete suggestion. I'm not sure what the autocomplete handler is wanting to delineate between items. Undefined is probably showing up because one of your items couldn't be found. You should use your browser's Developer Tools to debug what is getting sent.
Also, if you wanted the option's text rather than the value
then you'll need to access the .text()
rather than the .val()
of the select drop down.
Update: This post might have something to say about what autocomplete is expecting.
Upvotes: 1
Reputation: 9211
I think to pass in additional parameter for bassistance's autocomplete, the only way is to modify the autocomplete.js file. I did something similar before, but the method is quite hardcoding. Posted below for your reference (it's around line 376):
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
data: $.extend({
member_type: ($("#member_type").length != 1)?$("#member_type").val():-1,
q: lastWord(term),
limit: options.max
}, extraParams),
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
I only added one line to the original code, at line 10: member_type: ...
.
Take note that I pass in "-1" if the object is not found on that page to prevent javascript error.
Hope it helps!
Upvotes: 1