Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a text box by selecting from a drop down

Status
Not open for further replies.

nsukari

Technical User
Jul 17, 2002
26
0
0
US
There are two columns in my table "Programs", SPM ID and Program Name. I need to be able to automatically populate the "Program Name" by selecting the SPM ID from the drop-down list.

How can I do this?

Thanks for the help.
 
You'd probably need to use javascript.

Have the drop-down's onChange event call a function that simply sets the text of the "Program Name" form field to the value you want.

Since you probably want the SPM ID as a value (ie - the dropdown value will need to be the ID), you would want the function to check that value against an array. But you can have ColdFusion build the array pretty easily.

Code:
<script type=&quot;text/javascript&quot; language=&quot;JavaScript&quot;>
  var productNameArray = new Array();
  <CFOUTPUT query=&quot;qryPrograms&quot;>
     productNameArray[#qryPrograms.SPM_ID#] = &quot;#qryPrograms.PROGRAM_NAME#&quot;;
  </CFOUTPUT>

  function populateProductField(spmID){
     document.forms[&quot;formname&quot;].textProductName.value = productNameArray[spmID];
     return true;
  }
</script>

<form id=&quot;productForm&quot; name=&quot;productForm&quot; ...>
<select id=&quot;dropdownID&quot; name=&quot;dropdownID&quot; onchange=&quot;javascript: populateProductField(this.value);&quot;>
   <CFOUTPUT query=&quot;qryPrograms&quot;>
     <option value=&quot;#qryPrograms.SPM_ID#&quot;>#qryPrograms.SPM_ID#</option>
   </CFOUTPUT>
</select>

<input type=&quot;text&quot; id=&quot;textProductName&quot; name=&quot;textProductName&quot;>
   :
</form>

or something like that.


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top