Click to See Complete Forum and Search --> : Menu Swapper in a form


johnnymack
03-27-2003, 08:34 PM
I want to use the "Menu Swapper" code in a form on my site. Getting the menus in there is the easy part but when I hit submit I get nothing. I went to the guy's page that made the code and he said that you will get no results on submitting unless you either A) hilight everything in the right hand menu and then submit or B) use a SelectAll command to select and submit everything in the righthand menu. Well I dont want to do A and I don't know how to do B! Help!

Jona
03-27-2003, 08:44 PM
You mean select all on the page? document.all.select();

johnnymack
03-27-2003, 08:47 PM
no just in one of the menu boxes.

the menu on the left has many choices, you choose and move them to the blank menu on the right. in order for the items that you select to be sent via the submit button, you have to do a selectall on the menu on the right.

Jona
03-27-2003, 09:08 PM
Okay. Can you show me some code?

johnnymack
03-27-2003, 09:11 PM
I'm using the code right off this site:


<!-- TWO STEPS TO INSTALL MENU SWAPPER:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Phil Webb (phil@philwebb.com) -->
<!-- Web Site: http://www.philwebb.com -->

<!-- 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>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name="combo_box">
<table><tr><td>
<select multiple size="10" name="list1" style="width:150">
<option value="12">Alabama</option>
<option value="54">Alaska</option>
<option value="65">Arizona</option>
<option value="45">Arkansas</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<">
<input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>">
</td>
<td>
<select multiple size="10" name="list2" style="width:150">
</select>
</td></tr></table>
</form>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 4.75 KB -->

Jona
03-27-2003, 09:33 PM
The code works fine on my IE6.

johnnymack
03-27-2003, 09:42 PM
that code is fine, i have the menus and can switch things back and forth. what I WANT is to be able to select a few things and then hit submit...and that doesn't work.

Jona
03-27-2003, 09:48 PM
I still don't get it. I selected multiple options and the code still worked.

johnnymack
03-27-2003, 09:52 PM
what i want is to select multiple items and then hit submit, having those items which i've selected emailed to me.

the site where that code comes from says that what i want will only work if you hilight all in the right hand box and hit submit

OR

if you use a selectall on that righthand box...and this is what i want to use.

sorry this has been so confusing! thanks for the help!

Jona
03-27-2003, 09:55 PM
Okay, maybe...

for(x=0;x<document.formName.selectboxName.options.length;x++){
document.formName.selectboxName.options[i].select();
}

johnnymack
03-27-2003, 10:16 PM
forgive me for being so retarted, i'm not a pro, just a novice. i took your code there and put it up in the <head> section of my code, is that correct? i also changed the formname to my form's name and selectboxname to the list's name.

if that is all i had to do, it still doesn't work lol. i still get the error that i have left list2 blank.

Jona
03-27-2003, 10:20 PM
You can't select BOTH optoins from each select box. Yes, that could should've worked (if inside of a function, of course).

johnnymack
03-27-2003, 10:31 PM
I honestly don't know what you mean by you can't select both options from each select box. Here is the complete code of the page:

<html>
<HEAD>
<script language="JavaScript">
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;
}

}
function selectAll(box) {
for(var i=0; i<box.length; i++) {
box.options[i].selected = true;
}
}
for(x=0;x<document.form1.list2.options.length;x++){
document.form1.list2.options[i].select();
}
</script>
</HEAD>
<title>Submit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--


function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
</head>

<body bgcolor="#FFFFF">
<div align="center">
<p>&nbsp;</p>
<p>&nbsp; </p>
<form name="form1" method="post" action="http://www.masterspool.net/cgi-bin/formmail.cgi">
<input TYPE=hidden NAME="recipient" VALUE="entries@masterspool.net">
<input type=hidden NAME="redirect" value="http://www.masterspool.net/submitted.htm">
<input type=hidden NAME="required" VALUE="list2[]">
<div align="left">
<p>&nbsp;</p>
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td>
<select name="list1[]" size="10" multiple id="list1[]" style="width:150">
<option value="12">Alabama</option>
<option value="54">Alaska</option>
<option value="65">Arizona</option>
<option value="45">Arkansas</option>
<option value="2">California</option>
<option value="6">Colorado</option>
</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.elements['list2[]'],this.form.elements['list1[]'])" value="<<">
<input type="button" onClick="move(this.form.elements['list1[]'],this.form.elements['list2[]'])" value=">>">
</td>
<td>
<select name="list2[]" size="10" multiple id="list2[]" style="width:150">
</select>
</td>
</tr>
</table>
<p>
<input type="submit" name="submit_button" value="Submit">
<p>&nbsp;</p><p>
<font face="Geneva, Arial, Helvetica, sans-serif"> </font></p>
</div>
<div align="left"><font face="Geneva, Arial, Helvetica, sans-serif"></font> </font>
<p>&nbsp; </p>
</div>
</form>
</div>
<div align="center">
<p align="left">&nbsp;</p>
<div align="left"></div>
</div>
</body>
</html>

johnnymack
03-28-2003, 07:15 PM
bump

acamposv
10-10-2006, 03:09 PM
hi, you can move the selected options from one box to thew other but in te second combo it didnt show the selected options, what could it happen here???