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!

Dependant text field

Status
Not open for further replies.

NickyJay

Programmer
Sep 1, 2003
217
GB
Hi All,

Hope this is the right forum!

I have a form for our it staff to fill out when a piece of equipment is brought back in. On my form is a select box that has the ID of the equipment and displays the name of the staff allocated as the owner.

I want to be able to display the email of the seelcted person in a text box once the person is selected from my dropdown menu - all pulled out of a db by a coldfusion query. Am i right in thinking javascript is the answer?

I already have a text box that displays the selected ID number (to be hidden on the page for other uses when all testing is completed.) This works on the onFocus property of the field after the select menu.

Please help!
Nicola
 
Hi

Nicola said:
Am i right in thinking javascript is the answer?
Probably.

The question would be, how many addresses there are and how much you want to keep them secret.

You can simply add the mail addresses in the [tt]title[/tt] attributes of the corresponding [tt]option[/tt]s :
Code:
<select onclick="document.getElementById('email').value=this.options[this.selectedIndex].title">
<option value="" selected="selected">- select -</option>
<option value="id1" title="first@example.com">One</option>
<option value="id2" title="second@example.com">Two</option>
<option value="id3" title="third@example.com">Three</option>
</select>

<input type="text" id="email">
Or you can put the mail addresses in an associative array :
Code:
<script type="text/javascript">
var address={
  '':'',
  'id1':'first@example.com',
  'id2':'second@example.com',
  'id3':'third@example.com'
}
</script>

[gray]<!-- ... -->[/gray]

<select onclick="document.getElementById('email').value=address[this.options[this.selectedIndex].value]">
<option value="" selected="selected">- select -</option>
<option value="id1">One</option>
<option value="id2">Two</option>
<option value="id3">Three</option>
</select>

<input type="text" id="email">
Or you can keep the mail addresses on the server and request only the needed one with AJAX :
Code:
<select onclick="document.getElementById('email').value=AJAX('[URL unfurl="true"]http://example.com/givememail/?id='+this.options[/URL][this.selectedIndex].value)">
<option value="" selected="selected">- select -</option>
<option value="id1">One</option>
<option value="id2">Two</option>
<option value="id3">Three</option>
</select>

<input type="text" id="email">
Note that the above AJAX call is an example, actually it depends on the library you will use.

Feherke.
 
Hiya, thanks for responding,

The email addresses in question are work email addresses, so not secret at all, also, they are pulled out in my db query, i just need a way to link the correct address to the selected value from my select menu - or is an array a better way of doing this? Problem is where a new member of staff is added, i would then have to update the array for each new member, rather that just the call to my db???
 
Hi

So far we have no idea about how new members are added to your database.

Please post the code you have so far ( preferably HTML and JavaScript only, no ColdFusion, no CSS ) and give us details about how the new users are added ( on the same page, a different page, a different page opened in pop-up ).

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top