[Javascript] select values to input text problems

Chris Jensen cj at nvisionusa.net
Fri Mar 30 08:05:16 CST 2001


i'm trying to get values from a <select> input to populate a list of <input type=text> boxes.  what the page is supposed to do is be able to pick certain values from a select drop-down, add the values to a hidden field while adding the option text to the text field.  the function is supposed to get the selected option value and option text and put in the appropriate form for input into a database.

perhaps my DOM naming is wrong, i've not done too much work in javascript and my syntax is bad.  any tips would be helpful!  


here's my test code:

<html>

<head>

<script language="JavaScript">

nextBoxNum = 0;

function NextBox(form) {

var nextBox = nextBoxNum;

for (var i = 0; i < form.left.options.length; i++) {
 if (form.left.options[i].selected) {
document.all.bottomform[nextBox].value = form.left.options[i].text;
nextBox++;
document.all.bottomform[nextBox].value = form.left.options[i].value;
nextBox++;

}
}
nextBoxNum = nextBox;
}


</script>


</head>


<body bgcolor=#ffffff>

<table cols=2 cellspacing=10 width="100%">
<tr>
 <td width="50%">
 <form name="leftform" action="#" method=get>
 <select name="left" size=4>
  <option value="value1">Value 1
  <option value="value2">Value 2
  <option value="value3">Value 3
  <option value="value4">Value 4
 </select>
 <input type="button" name="button" value="test" onClick="NextBox(this.form)">
 </form>
 </td>
</tr>
<tr>
 <td width="50%">
 <form name="bottomform" action=#>
 <input type="text" value="" id="0" name=1><br>
 <input type="text" value="" id="1" name=1b><br><br>
 <input type="text" value="" id="2" name=2><br>
 <input type="text" value="" id="3" name=2b>
 
 </form>
 </td>
</tr>



</table>


</body>
</html>

TIA!

chris
-- 
---------------------------------------
c h r i s t o p h e r . a . j e n s e n
---------------------------------------
n Vision/usa inc.
w: http://www.nvisionusa.com
e: cj at nvisiongr.com
p: 6164566566
f: 6164566599
-- 
---------------------------------------
c h r i s t o p h e r . a . j e n s e n
---------------------------------------
n Vision/usa inc.
w: http://www.nvisionusa.com
e: cj at nvisiongr.com
p: 6164566566
f: 6164566599





More information about the Javascript mailing list