House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home / Groups / JQuery

Bind Value to textbox

Author:
Adam Parker
02/20/2012 12:08 PM

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.


Search jquery

May 20, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference