passing arrays to javascript functions..
Posted: Wed Oct 30, 2002 10:48 am
Hey all,
I'm having some problems with a webapp i'm working on. My problem comes using a script i found on the web at http://javascript.internet.com/forms/menu-swapper.html
i've taken the code and actually need to use this twice on my page.. however.. i don't think that's what's causing my problem..
What i think my problem is, is that in order for php to take all the values out of a multiple select box(well at least the only way i've done it) is that the select box must be named like an array (i.e. selBox[]) well.. when i prepare the select boxes in the form and rename them and all of the places they are reference in the click events.. the script stops working.. is there any way that any of you know that could get me around this?? maybe having the function accept an array.. i'm kinda lost at this point and any help is greatly appreciated..
my abbreviated code is below..
Thanks.
Will
Javascript function....
php and html form..
the page that the data is passed to.. contains..
still nothing prints out..
I'm having some problems with a webapp i'm working on. My problem comes using a script i found on the web at http://javascript.internet.com/forms/menu-swapper.html
i've taken the code and actually need to use this twice on my page.. however.. i don't think that's what's causing my problem..
What i think my problem is, is that in order for php to take all the values out of a multiple select box(well at least the only way i've done it) is that the select box must be named like an array (i.e. selBox[]) well.. when i prepare the select boxes in the form and rename them and all of the places they are reference in the click events.. the script stops working.. is there any way that any of you know that could get me around this?? maybe having the function accept an array.. i'm kinda lost at this point and any help is greatly appreciated..
my abbreviated code is below..
Thanks.
Will
Javascript function....
Code: Select all
<script language="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookupїtbox.optionsїi].text] = tbox.optionsїi].value;
arrTboxїi] = tbox.optionsїi].text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookupїfbox.optionsїi].text] = fbox.optionsїi].value;
if (fbox.optionsїi].selected && fbox.optionsїi].value != "") {
arrTboxїtLength] = fbox.optionsїi].text;
tLength++;
}
else {
arrFboxїfLength] = fbox.optionsїi].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookupїarrFboxїc]];
no.text = arrFboxїc];
fboxїc] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookupїarrTboxїc]];
no.text = arrTboxїc];
tboxїc] = no;
}
}
// End -->
</script>Code: Select all
<table width="408" >
<tr>
<td width="180">
<select name="selBox1" size="5" multiple onDblClick="move(this.form.selBox1,this.form.selBox2ї])">
<?
$SQL = "SELECT * table ORDER BY field";
$result = mysql_query($SQL);
while ($row = mysql_fetch_array($result))
{?>
<option value="<?=$rowї0]?>"><?=$rowї1]?></option>
<? } ?>
</select>
</td>
<td>
<input name="button" type="button" onClick="move(this.form.selBox2ї],this.form.selBox1)" value="<<">
<br>
<input name="button" type="button" onClick="move(this.form.selBox1,this.form.selBox2ї])" value=">>">
</td>
<td width="175"> <select name="selBox2ї]" size="5" multiple id="selBox2ї]" style="width:175" onDblClick="move(this.form.selBox2ї],this.form.selBox1)">
</select> </td>
</tr>
</table>Code: Select all
echo '<pre>';
print_r($HTTP_POST_VARSї'selBox2']);
echo '</pre><br>';