...

View Full Version : form swapper -- please help



esthera
05-30-2005, 09:36 AM
I am using the form swapper found
http://javascript.internet.com/forms/form-swapper-2.html

The problem is that when I submit the form -- when (in asp) i do request.form("list2") -- it finds list2 as blank.

Why? and what can I do to fix?

glenngv
05-30-2005, 11:04 AM
Are you using POST as form method? If the method is not specified, the default is GET. You need to set it to POST to use Request.Form.

esthera
05-30-2005, 11:22 AM
yes i changed to post

and anyway i tried with just request("list2") and its' teh same problem.

what am i doing wrong? is this supposed to work for submitting.

glenngv
05-30-2005, 11:26 AM
Is this an upload form? If it's an upload form, the form enctype is multipart/form-data and Request.Form will not work. Posting related codes will help.

esthera
05-30-2005, 11:34 AM
no a regular form

<form name="handle" method="post" action=savetranslators.asp>

then the list boxes and submit
that's it

esthera
05-30-2005, 11:56 AM
ok -- what i was doing wrong was I wansn't selecting the items in the second box before submitting.

Is there anyway to automatically have them all selected on submit?

glenngv
05-30-2005, 12:20 PM
function selectAll(oSel){
var len = oSel.options.length;
for (var i=0; i<len; i++){
oSel.options[i].selected = true;
}
}
...
<form onsubmit="selectAll(this.list2)">

But for a quick moment, the highlighting will be visible to the user.
If that bothers you, you can just have a hidden text field that contains the added items.

function getSelectedItems(oSel){
var len = oSel.options.length;
var hid = oSel.form.hiddenList;
for (var i=0; i<len; i++){
hid.value = ((hid.value!="") ? "," : "") + oSel.options[i].value;
}
}
...
<form onsubmit="getSelectedItems(this.list2)">
<input type="hidden" name="hiddenList" />

Then in action page, retrieve the value of the hidden field and not the combo box:

<%
dim list, arrList
list = request.form("hiddenList")
arrList = split(list, ",")
for each item in arrList
response.write item & "<br />"
next
%>

esthera
05-30-2005, 12:40 PM
thanks for your help.

I'm doing the hidden list option

it is writing out in the asp

,297 (297 is the second id) it's basically not showing the first id selected -- or actaully always showing , and only one of the values.

glenngv
05-30-2005, 01:27 PM
Sorry I forgot the + sign.

for (var i=0; i<len; i++){
hid.value += ((hid.value!="") ? "," : "") + oSel.options[i].value;
}

It's also good to reset the hidden field so that values don't add up when the page is submitted again.


hid.value = ""; //reset
for (var i=0; i<len; i++){
hid.value += ((hid.value!="") ? "," : "") + oSel.options[i].value;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum