PDA

View Full Version : Simple form issue



Clarissa
03-20-2012, 10:35 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem:

I was kindly provided with a modification for this script a while ago, specifically to be able to submit form data via a <select> drop-down list:


<form method="post" onsubmit="ajaxpage('submit.php?id=$ID&FORM1='+this.elements.FORM1.value+'&FORM2='+this.elements.FORM2.value,'$ID');return false;">

<select name="FORM1" size="3">
<option value="Value-1">Value-1</option>
<option value="Value-2">Value-2</option>
<option value="Value-3">Value-3</option>
</select>

<select name="FORM2" size="3">

<option value="Value-4">Value-4</option>
<option value="Value-5">Value-5</option>
<option value="Value-6">Value-6</option>
</select>

<input type="submit" value="submit" name="submit">

</form>

Everything still works fine, I just now need to be able to do the exact same thing with multiple checkboxes, I've tried a variety of approaches but none have worked.

Essentially something like this:


<form method="post" onsubmit="ajaxpage('submit.php?id=$ID&FORM1='+this.elements.FORM1.value+'&FORM2='+this.elements.FORM2.value,'$ID');return false;">

<input type="checkbox" name="FORM1[]" value="Value-1" />Value-1<br />
<input type="checkbox" name="FORM1[]" value="Value-2" />Value-2<br />
<input type="checkbox" name="FORM1[]" value="Value-3" />Value-3<br />

<input type="checkbox" name="FORM2[]" value="Value-4" />Value-4
<input type="checkbox" name="FORM2[]" value="Value-5" />Value-5
<input type="checkbox" name="FORM2[]" value="Value-6" />Value-6


Any ideas? Thanks.

vwphillips
03-20-2012, 12:13 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
/*]]>*/

function Inputs(frm){
var els=frm.elements,v1=false,v2=false,z0=0;
for (;z0<els.length;z0++){
if (els[z0].name=='FORM1[]'&&els[z0].checked){
v1=els[z0].value;
}
if (els[z0].name=='FORM2[]'&&els[z0].checked){
v2=els[z0].value;
}
}
if (v1&&v2){
alert('submit.php?id=$ID&FORM1='+v1+'&FORM2='+v2)
// ajaxpage('submit.php?id=$ID&FORM1='+v1+'&FORM2='+v2,'$ID');
}
}


</script></head>

<body>
<form method="post" onsubmit="Inputs(this);return false;">

<input type="radio" name="FORM1[]" value="Value-1" />Value-1<br />
<input type="radio" name="FORM1[]" value="Value-2" />Value-2<br />
<input type="radio" name="FORM1[]" value="Value-3" />Value-3<br />

<input type="radio" name="FORM2[]" value="Value-4" />Value-4
<input type="radio" name="FORM2[]" value="Value-5" />Value-5
<input type="radio" name="FORM2[]" value="Value-6" />Value-6
<input type="submit" name="" value="Submit" />
</form>
</body>

</html>