Click to See Complete Forum and Search --> : Request: Pass info from Select Tag Options to a Textarea


F-Rott
02-05-2003, 05:08 PM
Hi guys! I was hoping some kind soul could help me here:

I was wanting to have a form where I select an option, and with onChange, have the value of that option pasted into a textarea box. I basically get how to do it with an Anchor tag where you click the link and the value is pasted, but I can't seem to replace the separate links which can get bulky when there's a lot of choices with a more streamlined Select tag Options approach.

Any help would be appreciated! :D

khalidali63
02-05-2003, 05:11 PM
suppose ur selection boxes name is
listBox
and your textarea name is
textArea
here is how you get the selected value from the list box

var index = document.formName.listBox.selectedIndex;
var selectedValue = document.formName.listBox[index].value;

now put this value in the text area

document.formName.textArea.value =selectedValue;

cheers

Khalid

F-Rott
02-05-2003, 06:08 PM
Thanks for the reply Khalid!

I messed around with it, but I couldn't figure out how to get it to work. I'm a newbie...:(

Here's what I got. I know it's wrong, but I can't seem to figure it out - I'm trying to learn, though!

<script language="JavaScript">
<!-- Begin
var index = document.formName.listBox.selectedIndex;
var selectedValue = document.formName.listBox[index].value;
var textArea = document.listBox.textArea.value = selectedValue;
// End -->
</script>

<FORM name=formName method=post>
<select name=listBox>
<option>
<option value="Selection 1">Selection 1
<option value="Selection 2">Selection 2
<option value="Selection 3">Selection 3
<option value="Selection 4">Selection 4
</select><br>
<TEXTAREA cols=45 name=textArea rows=10></TEXTAREA>
</form>

khalidali63
02-05-2003, 06:26 PM
you were not that farr off.
By the way try to put all the element names in small letters and all the atribute values within double outes.


<script type="text/javascript">
/**************************************************************************************
Author : Khalid Ali
Date :
Version : 1.1
Company : NetTech
Description :
***************************************************************************************/
function process(){
var index = document.formName.listBox.selectedIndex;
var selectedValue = document.formName.listBox[index].value;
var textArea = document.formName.textArea.value = selectedValue;
}
</script>

<FORM name="formName" method="post">
<select name="listBox" onchange="process();">
<option>
<option value="Selection 1">Selection 1
<option value="Selection 2">Selection 2
<option value="Selection 3">Selection 3
<option value="Selection 4">Selection 4
</select><br>
<textarea cols="45" name="textArea" rows="10"></textarea>
</form>

F-Rott
02-06-2003, 12:44 AM
Wow! Thanks. :D