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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto update text field with related value from select box

Status
Not open for further replies.

NickyJay

Programmer
Sep 1, 2003
217
GB
Hi guys,

I need help mixing js and cf - on my form i have a disabled text box that i need to update when a value is picked from a select box.

I have a query that pulls out the ID of a pc, plus the username it is allocated to and their email address. My select displays the username, when one is selected i want my text box to be populated with the corresponding email address - how can i do this?

I have another text box on the form that is populated with the pc id number when the username is picked from the same select, but how do get the email address to display??

Code:
<!--- query the database for the laptop numbers and users that havent yet been returned--->  
<cfquery name="qryLaptop" datasource="StaffBadges" >
	SELECT u.UpgradeFK, l.ID, l.LAPno, l.BadgeName, l.EmailAddress
	FROM tblUpgradeLaptop AS u 
	RIGHT OUTER JOIN LaptopNames AS l ON u.LaptopFK = l.ID
	WHERE (u.LaptopFK IS  NULL) 
	AND (l.ID IS NOT NULL)
	ORDER BY LAPno
</cfquery> 

<select name="laptopNo" size="1" >
	<option value="0">Select from...</option>
    <cfoutput query="qryLaptop"> 
      <option value="#ID#">#LAPno# - #EmailAddress#</option>
    </cfoutput> 
  </select>
  <input type="text" disabled name="laptopID" />
  <input type="text" disabled name="email"/><br />
  <label>Handed In On: </label>
  <input type="text" size="10" name="Date_In" value="<cfoutput>#TodayIS#</cfoutput>" onFocus="this.form.laptopID.value=form.laptopNo.options[form.laptopNo.selectedIndex].value;"/>
Any help is gratefully appreciated!!

Nicola
 
From your code, it's obvious that you understand the JS document hierarchy. All you need now is a place to hold the corresponding email addresses, so create an output loop (or use your existing CFOUTPUT) that populates hidden text fields or an array. Use the primary key from the table to name the array key or form field. Write a function that accepts the key from the selected item and retrieves the value from the field or array based on the key. If you use hidden fields, you'll have to construct the field name, e.g. "email_"&ID.

This should get you started. If you have specific questions about JS syntax etc., you should post them to the Javascript forum.

HTH,

Phil H.
Some Bank
-----------
Time's fun when you're having flies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top