Jump to content

Auto suggest submit ID not title


Presto-X

Recommended Posts

I’m having a developer help build a form with an auto suggest search field to search for a category, what I would like to know is, is it possible to display the category titles in the suggestion drop down and then when the form is submitted, submit the category ID, not the title that is displayed in the field?  Also if anyone knows of a script that is already written that does this (submits ID instead of title) please let us know.

Link to comment
https://forums.phpfreaks.com/topic/220292-auto-suggest-submit-id-not-title/
Share on other sites

As the autosuggest will display the text, you and store the ids with the value in a global array, and use that. For example:

 

suggestValues = []
suggestValues['suggested this'] = 1; // the ID is 1
suggestValues['suggested that'] = 2; // the ID is 2
function getSuggestedValueID (suggestedValue)
{
  return suggestValues[suggestedValue];
}

 

Pass the value that the user submits into the getSuggestedValue function, and this will output the ID for that value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.