...

View Full Version : copy a part of a dropdown box selection to a textbox



anarchoi
05-07-2007, 02:33 AM
Hi,

I have a form script with a dropdown box listing a lot of albums in this format:
"The Band - Name of the album"

there is another feild the users have to fill, it's a textbox where you have to write the band name. This is just making things harder for my members since the band name is already written in the album name, but filling the textbox is required for the process.

what i would like to do is the following:

When a user either click the submit button, or automaticaly when the dropdown box value is changed:
Automaticaly copy ONLY the text BEFORE the " - " from the dropdown to the textbox


Example:
If user select entry "abcdefg - hijklmnopqrstuvwxyz" from the dropdown, then:
Write "abcdefg" in the textbox



THANKS A LOOOT!

Arty Effem
05-07-2007, 03:36 AM
Example:
If user select entry "abcdefg - hijklmnopqrstuvwxyz" from the dropdown, then:
Write "abcdefg" in the textbox

Try this (totally untested). Note that it acts on the option text, not value.

<select onchange='this.form.textField.value=this.options[this.selectedIndex].text.replace(/^([^\-]+)\s*.+$/,"$1")'>
Where textField is the name of the receiving text field in the same form.

anarchoi
05-07-2007, 04:04 AM
AWESOME!!!

thanks a LOT!!!

working perfectly ;)

anarchoi
05-07-2007, 04:30 AM
this seems to only affect elements in the same form than the dropdown

is it possible to make it work with a textbox in a different <form>

Arty Effem
05-07-2007, 11:34 AM
this seems to only affect elements in the same form than the dropdown

is it possible to make it work with a textbox in a different <form>

Just change
this.form.textField.valueto
document.forms.formName.textField.value



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum