...

View Full Version : Write to TextArea



rabit
06-03-2009, 06:18 PM
edit: figured out the first part of this, still need help in second post.

I am a complete novice with JavaScript and haven't even attempted anything in about a year. What I am trying I know I used to be able to do I just can not remember anything about it.

I am just trying to make 2 drop downs. When you choose a one of the options, I want that option's value to appear in the text area below, then I want the text area to go to a new line for the next drop down's value.

I apologize for being so noobish here. I am sure it will begin to come back to me the more I read. Its just easier for me to learn if I can see an example. I have done as much as I can remember. I am pretty sure i need to set IDs for my drop down form tag, but I can't remember for sure. Any help would be greatly appreciated.


<form>
<p><select size="1" name="vote1">
<option selected>-</option>
<option value="Vote1-1">1</option>
<option value="Vote1-2">2</option>
<option value="Vote1-3">3</option>
<option value="Vote1-4">4</option>
<option value="Vote1-5">5</option>
</select></p>


<p><select size="1" name="vote1">
<option selected>-</option>
<option value="Vote2-1">1</option>
<option value="Vote2-2">2</option>
<option value="Vote2-3">3</option>
<option value="Vote2-4">4</option>
<option value="Vote2-5">5</option>
</select></p>

<p><textarea rows="7" name="copy" cols="30"></textarea></p>
</form>

rabit
06-03-2009, 06:26 PM
Ok I have this much..


However, only problem I am having with this is that I don't want vote2 to overwrite vote1, in the text area. I want vote2's value to appear on a new line below vote1 in the text area.



<HEAD>
<META http-equiv=Content-Type content="text/html">
<SCRIPT language=javascript>
function showValue(sel) {
var els = sel.form.elements;
els.copy.value = sel.value + "\n";
els = null;
sel = null;
}

</SCRIPT>
<form>
<p>
<select size="1" name="vote1" onchange="showValue(this);">
<option selected>-</option>
<option value="Vote1-1">1</option>
<option value="Vote1-2">2</option>
<option value="Vote1-3">3</option>
<option value="Vote1-4">4</option>
<option value="Vote1-5">5</option>
</select>
</p>
<p>
<select size="1" name="vote1" onchange="showValue(this);">
<option selected>-</option>
<option value="Vote2-1">1</option>
<option value="Vote2-2">2</option>
<option value="Vote2-3">3</option>
<option value="Vote2-4">4</option>
<option value="Vote2-5">5</option>
</select>
</p>
<p><textarea rows="7" name="copy" cols="30"></textarea></p>
</form>

Philip M
06-03-2009, 06:33 PM
Like this?



<form name = "myform">
<p><select size="1" name="vote1" id = "vote1" onchange = "putInText(this)">
<option selected>-</option>
<option value="Vote1-1">1</option>
<option value="Vote1-2">2</option>
<option value="Vote1-3">3</option>
<option value="Vote1-4">4</option>
<option value="Vote1-5">5</option>
</select></p>

<p><select size="1" name="vote2" id = "vote2" onchange = "putInText(this)">
<option selected>-</option>
<option value="Vote2-1">1</option>
<option value="Vote2-2">2</option>
<option value="Vote2-3">3</option>
<option value="Vote2-4">4</option>
<option value="Vote2-5">5</option>
</select></p>

<p><textarea rows="7" name="copy" id = "copy"cols="30"></textarea></p>
</form>

<script type = "text/javascript">

function putInText(which) {
var a = which.value;
var txt = document.getElementById("copy").value;
document.getElementById("copy").value = txt + a + "\n";
}

</script>

There is of course nothing to prevent the same selection being made twice.

Why are you using several forms?

<SCRIPT language=javascript> is lomg deprecated and obsolete. Use <script type = "text/javascript"> instead.


Brevior saltare cum deformibus mulieribus est vita - Life is too short to dance with ugly women

rabit
06-03-2009, 06:37 PM
Exactly! its more complicated than I thought it had to be. I will comb it over and try to figure out how it works. I really appreciate the help, thank you!

rabit
06-03-2009, 06:46 PM
Why are you using several forms?


Just 2. It has been a while since I have sought help and I wasn't sure what forum would be the best. Apparently they are both great. I didn't mean to clog either board up.

Philip M
06-03-2009, 06:48 PM
Just 2. It has been a while since I have sought help and I wasn't sure what forum would be the best. Apparently they are both great. I didn't mean to clog either board up.

I said FORMS not FORUMS!

But cross or multiple posting is discouraged here.

rabit
06-03-2009, 06:49 PM
I said FORMS not FORUMS!

But cross or multiple posting is discouarged here.

Oh well, apparently I'm an idiot all around. Well either way I appreciate your help and look forward to learning more.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum