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

Populate Textbox With Options Selected 1

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
An HTML Form has a drop-down list in which the options are listed by retrieving records from a backend (for which I am using ASP). The options in the drop-down list are displayed as

LastName FirstName (e-mail address)

The value of each option is a whole number. This HTML Form also includes a textbox. What I want is when a user chooses one of the options from the drop-down list, the e-mail address of that chosen option should be populated in the textbox. If the user selects another option then the e-mail address of this 2nd option selected should be populated in the textbox. But note that the e-mail address of the 1st option should be kept as it is in the textbox; the e-mail address of the 2nd option selected should just get appended to the textbox (after the e-mail address of the 1st option selected) & the 2 e-mail addresses should be seperated by a semi-colon (;). Here's an example:

Suppose a user selects the option Bond James
Code:
(james@bond.com)
from the drop-down list. The value of the textbox should be

Code:
james@bond.com

Next the user selects another option Horne Matt
Code:
(matt@horne.com)
from the drop-down list. Now the value of the textbox should change to

Code:
james@bond.com; matt@horne.com

The user selects yet another option Grant Hugh
Code:
(hugh@grant.com)
as the 3rd option from the drop-down, then the value of the textbox should now change to

Code:
james@bond.com; matt@horne.com; hugh@grant.com

In short, the e-mail addresses should be delimited using a semi-colon (;) when there are more than 1 e-mail address in the textbox. How do I do this using JavaScript?

Thanks,

Arpan
 
So something like this?

<form>
<select onchange=&quot;if(this.selectedIndex>0){this.form.t.value+=(this.form.t.value.length>0?';':'')+this[this.selectedIndex].text}&quot;>
<option>
<option value=&quot;1&quot;>james@bond.com
<option value=&quot;2&quot;>matt@horne.com
<option value=&quot;3&quot;>hugh@grant.com
</select>
<input name=&quot;t&quot;>
</form>

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Thanks, Adam, for your suggestion. It is working exactly as I wanted it to but there is a small hitch. Suppose from the drop-down list, I select the 1st option
Code:
james@bond.com
. The textbox value becomes

Code:
james@bond.com

Next I select the 2nd option which is
Code:
matt@horne.com
. The textbox value changes to

Code:
james@bond.com;matt@horne.com

Till this point, everything's working great but suppose I select the 1st option
Code:
james@bond.com
again from the drop-down list. This changes the textbox value to

Code:
james@bond.com;matt@horne.com;james@bond.com

Under such circumstances, the e-mail address
Code:
james@bond.com
gets appended to the textbox twice (since I had selected it 2 times). But I want to avoid repetition of the e-mail addresses in the textbox. If the e-mail address
Code:
james@bond.com
is selected more than once from the drop-down list, the textbox should still show
Code:
james@bond.com
ONCE & ONCE ONLY i.e. the value in the textbox should be

Code:
james@bond.com;matt@horne.com

How do I take care of this?

Thanks once again,

Regards,

Arpan
 
Ok, a small addition...

<form>
<select onchange=&quot;if(this.selectedIndex>0 && this.form.t.value.indexOf(this[this.selectedIndex].value)==-1){this.form.t.value+=(this.form.t.value.length>0?';':'')+this[this.selectedIndex].text}&quot;>
<option>
<option value=&quot;1&quot;>james@bond.com
<option value=&quot;2&quot;>matt@horne.com
<option value=&quot;3&quot;>hugh@grant.com
</select>
<input name=&quot;t&quot;>
</form>

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top