griffaw
asked on
Jquery Autocomplete submit id
I'm using Jquery autocomplete to search users. I need to display a users first and last name, but submit the userid only with the form.
Here's what I have now.
//format of data returned from ajaxsearch.asp. | as seperator
lastname, firstname, userid|lastname2, firstname2, userid
//the javascript
<script type="text/javascript">
$().ready(function() {
function log(event, data, formatted) {
$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#resu lt");
}
function formatItem(row) {
return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}
function formatResult(row) {
return row[0].replace(/(<.+?>)/gi , '');
}
$("#editid").autocomplete( "ajaxsearc h.asp", {
selectFirst: true
});
})
</script>
//the form field
<input type="text" name="editid" id="editid" />
Here's what I have now.
//format of data returned from ajaxsearch.asp. | as seperator
lastname, firstname, userid|lastname2, firstname2, userid
//the javascript
<script type="text/javascript">
$().ready(function() {
function log(event, data, formatted) {
$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#resu
}
function formatItem(row) {
return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}
function formatResult(row) {
return row[0].replace(/(<.+?>)/gi
}
$("#editid").autocomplete(
selectFirst: true
});
})
</script>
//the form field
<input type="text" name="editid" id="editid" />
ASKER
jmatix:
That works to pass the id only, but I need the selected user's name to appear in the text box and the id to be submitted by the form...possibly in a hidden field?
Another option would be to use your configuration and submit instantly on select...
That works to pass the id only, but I need the selected user's name to appear in the text box and the id to be submitted by the form...possibly in a hidden field?
Another option would be to use your configuration and submit instantly on select...
If this is the only input that you expect from the user, you can submit the form immediately after the user select a name. Otherwise, as you said, you need to populate the id into a hidden field, say, with id userid.
So the result handler has to be modified as:
$(#userid).val(dat[2]);
return (dat[0]+' '+dat[1]);
So the result handler has to be modified as:
$(#userid).val(dat[2]);
return (dat[0]+' '+dat[1]);
ASKER
jmatix:
Please post the entire script with your modification...I'm getting illegal character errors.
Thanks
Please post the entire script with your modification...I'm getting illegal character errors.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
jmatix:
Perfect!
How would I set the form to submit when a selection is made? I'm not sure how to do this on a text field.
Perfect!
How would I set the form to submit when a selection is made? I'm not sure how to do this on a text field.
Open in new window