Click to See Complete Forum and Search --> : passing values from one select(option) to another select(option)


beat
08-22-2005, 09:00 AM
Hi

Because of design reasons I have two different select tags (different width with css). How can I pass the selected value in select1? With alert I can see the value but I couldn't actualize the value.

<script type="text/javascript">
function sendoption () {
for (i = 0; i < document.xxForm.select2.length; ++i)
if (document.xxForm.select2.options[i].selected == true)
alert(document.xxForm.select2.options[i].value);
}
</script>

<form name="xxForm" method="post" action="">
<div id="m1">
<select name="select1" class="select">
<option value="a1">a1</option>
<option value="a2">a2</option>
</select>
</div>
<div id="m2">
<select name="select2" onChange="sendoption()">
<option value="b1">b1</option>
<option value="b2">b2</option>
</select>
</div>
</form>

Kind regards
Beat

rigadon
08-22-2005, 11:26 AM
Not really sure what you are asking? So far as I can tell when a user clicks on an entry in the second select box you want this value to be added to the first? In which case try this:

<script type="text/javascript">
function sendoption ()
{ var val = document.xxForm.select2.value;
var dest = document.xxForm.select1;
dest.options[dest.length] = new Option(val, val);
}
</script>

beat
08-24-2005, 01:10 AM
thank you rigadon, your script didn't work but I think it was my mistake. The problem was difficult to explain. Here the script how I could fix the problem:

function transfer() {
var defaultSelected = true;
var selected = true;
var optionName = new Option(document.xxForm.select2.options[document.xxForm.select2.selectedIndex].text,
document.xxForm.select2.options[document.xxForm.select2.selectedIndex].value,
defaultSelected, selected)
var length = document.xxForm.select1.length;
document.xxForm.select1.options[length] = optionName;

}

kind regards
beat