...

View Full Version : Insert text in textbox upon selecting list value



vorl
08-12-2005, 02:51 PM
hi

could someone help me to insert a piece of text in a text box when the user selects a particular value in a list field.

thanks

vorl

nikkiH
08-12-2005, 03:26 PM
At the most rudimentary...

<select onchange="doIt()" ...>



function doIt()
{
document.formname.elementname.value='some text value';
}

martin_narg
08-12-2005, 05:12 PM
Nikki is correct, as an addendum this example would insert the value of the select box into the text field.


<select onchange="document.theFormName.theTextBoxName.value=this.options[this.selectedIndex].value;">


m_n

vorl
08-13-2005, 07:27 PM
thanks

i have 'yes' and 'no' in the list. I only want the text to be inserted in the textbox when 'no' is selected. how would i do this?

thanks again

vorl

martin_narg
08-14-2005, 01:01 AM
<select onchange="if(this.options[this.selectedIndex].value=='no'){document.theFormName.theTextBoxName.value='no'}">
"">


hope this helps

m_n

vorl
08-14-2005, 03:17 PM
Hey Martin

sorry to be of nuisence but when i add the code a error appears which says there is a ')' missing. But i dont know where to put it; please show me where to put it?

Thanks again

vorl

martin_narg
08-14-2005, 03:21 PM
Humble apologies, the error was in my code i posted, i missed out the closing ) of the if statement.

try this:


<select onchange="if(this.options[this.selectedIndex].value=='no'){document.theFormName.theTextBoxName.value='no'}">
"">


apols

m_n

vorl
08-14-2005, 04:03 PM
thanks mate that totally worked!!

thanks for being patient

vorl :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum