SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Jun 14, 2004, 03:10 #1
need help with select box and javascript
Hi,
I am working on a project where I need the contents of a select box to be added to a textarea when a selection is clicked.
For example, say I have a list box with 10 elements that allows multiple selections by holding down CTRL and clicking whatever you want. I also have a textarea. How can I make the text of the selected elements of the select box appear in the textarea as they are selected?
Any help is appreciated.
Thanks,
Martin
-
Jun 14, 2004, 07:37 #2
- Join Date
- Apr 2002
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<form>
<select name="mySelect" multiple size="4" onchange="doThis(this)">
<option value="0"></option>
<option value="1">Apple</option>
<option value="2">Blueberry</option>
<option value="3">Cherry</option>
<option value="4">Durian</option>
<option value="5">Fig</option>
<option value="6">Guanabana</option>
<option value="7">Huckleberry</option>
<option value="8">Ilang Ilang</option>
<option value="9">Jackfruit</option>
</select><br><br>
<textarea name="myTextarea" cols="25" rows="6"></textarea>
</form>
<script>
function doThis(s){
var x = s.options;
var taValue = '';
for (i=0;i<x.length;o=i++){
if (x[i].selected)
taValue += x[i].text+'\n';
}
document.forms[0].myTextarea.value = taValue;
}
</script>
-
Jun 14, 2004, 07:51 #3
Thanks for your reply....thats sort of what i am looking for. However, there are 2 other things I probably should have mentioned in my post. I need the current contents of the textarea to stay there and i need the values from the select box to be added in the order they are selected.
Thanks,
Martin
-
Jun 14, 2004, 12:06 #4
- Join Date
- Jun 2003
- Location
- East Coast
- Posts
- 2,215
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
(edit): Looks like shoop already has the += ....
Use +=
For example, you already have the code to get the select value:
Code:var tArea = document.getElementById('textboxName') tArea.value += otherStuff;
█ Nick . all that we see or seem, is but a dream within a dream
█ Show someone you care, send them a virtual flower.
█ Good deals on men's watches
Bookmarks