|
Mailing Lists
|
Home /
Groups /
JQuery
Bind Value to textbox
Solved with:Adam Parker 02/20/12 01:38 P I have created a form where users input a part number and jQuery autosuggest pulls a list of similar part numbers to finish the whole part number. What I am trying to do is have a readonly textbox populate the part description so the user can visually confirm he has entered the desired part. With the current state of the code, the part numbers do appear, but the description does not get populated in the desired textbox. The form and jQuery are: <form action="index.cfm?action=reports:part.test" method="post"> <fieldset> <legend>test</legend> <p>Start typing a part number.</p> <p> <label for="partnum">Part Number: </label> <input type="text" id="partnum" name="partnum" /> <input readonly="readonly" type="text" id="partdescription" name="partdescription" /> </p> <p> <input type="submit" name="submit" value="Submit" /> </p> </fieldset> </form> <cfsavecontent variable="datatables_definitions"> <!-- added by user.list --> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> $(document).ready(function(){ $('#partnum').autocomplete( {source: function(request, response) { $.ajax({ url: "/reports/services/remote/partSuggest.cfc?method=lookUpPart&returnformat=json", dataType: "json", data: { search: request.term, maxRows: 10 }, success: function(data) { response(data); }, }) }, parse: function(data){ return $.map(data, function(item) { return { data: item, value: item, result: item }; }); } }); }); </SCRIPT> </cfsavecontent> <cfhtmlhead text="#datatables_definitions#" /> The CFC doing the work is: <cfcomponent output="false"> <cffunction name="lookUpPart" access="remote" returntype="any" > <cfargument name="search" type="any" required="false" default=""> <cfargument name="datasource" type="string" required="no" default="mydsn"> <!--- Define variables ---> <cfset var data=""> <cfset var result=ArrayNew(1)> <!--- Do search ---> <cfquery name="getPart" datasource="#arguments.datasource#"> SELECT top 20 partnum, partdescription FROM part WHERE partnum LIKE '%#trim(arguments.search)#%' ORDER BY partnum </cfquery> <!--- Build result array ---> <cfloop query="getPart"> <cfset returnStruct = StructNew() /> <cfset returnStruct["label"] = partnum /> <cfset returnStruct["partdescription"] = partdescription /> <cfset ArrayAppend(result,returnStruct) /> </cfloop> <!--- And return it ---> <cfreturn serializeJSON(result) /> </cffunction> </cfcomponent> How can I bind the partdesription data to the partdescription field once the part number is chosen? Thank you. Solved with: $('#partdescription').val(ui.item.partdescription);
|
May 25, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||