Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Form and frames interaction


Message #1 by "Paulo Fernandes" <paulofernandes@c...> on Fri, 9 Aug 2002 05:56:01 +0100
Hi,

I came across this code for a dual select list and it works just fine.

The problem is that I'm trying to get the second select list (the one
on the right) to be on another, so that when you click the button to
pass the value to the other select list you would pass the value to
another frame. Being mostly and ASP programmer, I do not know how to
do it.

I'm posting the code below. Can anyone help me out, please?

Thanks in advance for any prompt reply.

PauloF



<script language="JavaScript"><!--
function deleteOption(object,index) {
    object.options[index] = null;
}

function addOption(object,text,value) {
    var defaultSelected = true;
    var selected = true;
    var optionName = new Option(text, value, defaultSelected, selected)
    object.options[object.length] = optionName;
}

function copySelected(fromObject,toObject) {
    for (var i=0, l=fromObject.options.length;i<l;i++) {
        if (fromObject.options[i].selected)
 
addOption(toObject,fromObject.options[i].text,fromObject.options[i].valu
e);
    }
    for (var i=fromObject.options.length-1;i>-1;i--) {
        if (fromObject.options[i].selected)
            deleteOption(fromObject,i);
    }
}

function copyAll(fromObject,toObject) {
    for (var i=0, l=fromObject.options.length;i<l;i++) {
 
addOption(toObject,fromObject.options[i].text,fromObject.options[i].valu
e);
    }
    for (var i=fromObject.options.length-1;i>-1;i--) {
        deleteOption(fromObject,i);
    }
}
//--></script>

<form>

<table><tr><td>

<select name="select1" multiple size="7">
<option>zero
<option>one
<option>two
<option>three
<option>four
<option>five
<option>six
</select>

</td><td>

<input type="button" value=" > " onClick="if (document.images)
copySelected(this.form.select1,this.form.select2)">
<p>
<input type="button" value=" < " onClick="if (document.images)
copySelected(this.form.select2,this.form.select1)">
<p>
<input type="button" value=">>" onClick="if (document.images)
copyAll(this.form.select1,this.form.select2)">
<p>
<input type="button" value="<<" onClick="if (document.images)
copyAll(this.form.select2,this.form.select1)">

</td><td>

<select name="select2" multiple size="7">
</select>

</td></tr></table>

</form>


  Return to Index