Different user input boxes are automatically populated based on a value of the dropdown box.

R

reneeccwest

Different user input boxes are automatically populated based on a
value of the dropdown box.

Can anyone help me on that?
 
G

Grant Wagner

reneeccwest said:
Different user input boxes are automatically populated based on a
value of the dropdown box.

Can anyone help me on that?

<form name="myForm">
<input type="text" name="inputOne">
<input type="text" name="anotherInput">
<select name="mySelect" onchange="setInputs(this);">
<option value="None">Choose</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</form>
<script type="text/javascript">
var inputValues =
[
{
inputOne:'',
anotherInput:''
},
{
inputOne:'value for One',
anotherInput:'another value for One'
},
{
inputOne:'Two was picked',
anotherInput:'Tooooo'
}
];

function setInputs(selObj) {
var f = selObj.form;

var selectedItem = selObj.selectedIndex;

var inputs = inputValues[selectedItem];

for (var input in inputs) {
f.elements[input].value = inputs[input];
}
}
</script>

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
R

reneeccwest

thank you for your help!
but i meant...
Depends on the value of the combo box, text input boxes will be dynamic.
for example,
there are 5 text input boxes (let's name them as "inputOne", "inputTwo",
"inputThree", "inputFour", and "inputFive") and if the value of combox is
selected as "One",
then the first text input box ("inputOne") and the third input box
("inputThird")will be appeared, but rest of them will be disappeared.

if the value of combox is selected as "two",
then the second text input box ("inputsecond"), the fourth text input box
("inputFourth") and the five input box ("inputThird")will be appeared, but
rest of them will be disappeared.


Grant Wagner said:
reneeccwest said:
Different user input boxes are automatically populated based on a
value of the dropdown box.

Can anyone help me on that?

<form name="myForm">
<input type="text" name="inputOne">
<input type="text" name="anotherInput">
<select name="mySelect" onchange="setInputs(this);">
<option value="None">Choose</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</form>
<script type="text/javascript">
var inputValues =
[
{
inputOne:'',
anotherInput:''
},
{
inputOne:'value for One',
anotherInput:'another value for One'
},
{
inputOne:'Two was picked',
anotherInput:'Tooooo'
}
];

function setInputs(selObj) {
var f = selObj.form;

var selectedItem = selObj.selectedIndex;

var inputs = inputValues[selectedItem];

for (var input in inputs) {
f.elements[input].value = inputs[input];
}
}
</script>

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top