Jump to content


Photo

post input from multiple forms


  • Please log in to reply
3 replies to this topic

#1 ann

ann
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 14 September 2006 - 10:36 AM

Hi

I have a user input html page with multiple forms because the javascript won't work with one form or sub froms. My aim is to get the input data to a php script and I think the way to do that is have a final form in the html which posts all the input.

Problem, how do I get the input values from other forms into the final 'submit' from?  (don't remember where I got the syntax that I've commented out but it doesn't work anyway).  ???

Many thanks if you can help.

http://www.nematodes.../test_js5.shtml

My scripts

html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style type="text/css">	<!--.show {display:block;}.hide {display:none;}--></style>
< script type="text/javascript"><!--
function checkChangeAll(){
	if (document.buttonDemo.onOffButton.value==" Select all "){
		document.buttonDemo.onOffButton.value=" Clear all ";
		for (i=0; i<document.forms[0].length; i++){if(document.forms[0].elements[i].name.match(/org/)){document.forms[0].elements[i].checked = true;}}
	}
	else{
		document.buttonDemo.onOffButton.value=" Select all ";
		for (i=0; i<document.forms[0].length; i++){if(document.forms[0].elements[i].name.match(/org/)){document.forms[0].elements[i].checked = false;}}
	}
}
//--></ script>

</head>
<body onload="checkChangeAll()";>

< script type="text/javascript"><!--
window.onload=function() {
	obj=document.getElementById('abun')
	obj.className='hide';
	objs=document.getElementById('simi')
	objs.className='hide';
	rad=document.getElementsByTagName('input');
	for(c=0;c<rad.length;c++) {
		if(rad[c].name=='out') {
			rad[c].onclick=function() {
				if(this.value==0) {obj.className='show';objs.className='hide';}
				else {obj.className='hide';objs.className='show';}
			}
		}
	}
}//--></ script>


	<table class="tablephp2">
		<tr>
			<td>
				<form method="post" name="buttonDemo">  <!--form[0]-->
					<table>
						<tr height=20></tr>
						<tr>
							<td><div class="mainBig">Species to search</div></td>
							<td>
								<input type="Button" value=" Select all " name="onOffButton" onClick="checkChangeAll()">
							</td>
						</tr>
						<tr height=20></tr>
						<tr>
							<td><input TYPE="checkbox" NAME="org[0]" value="ACC">Ancylostoma caninum</input></td>
							<td><input TYPE="checkbox" NAME="org[1]" value="ALC">Ascaris lumbricoides</input></td>
							<td><input TYPE="checkbox" NAME="org[2]" value="ASC">Ascaris suum</input></td>
							<td><input TYPE="checkbox" NAME="org[3]" value="AYC">Ancylostoma ceylanicum</input></td>
						</tr><tr>
							<td><input TYPE="checkbox" NAME="org[4]" value="BMC">Brugia malayi</input></td>
							<td><input TYPE="checkbox" NAME="org[5]" value="DIC">Dirofilaria immitis</input></td>
							<td><input TYPE="checkbox" NAME="org[6]" value="GPC">Globodera pallida</input></td>
							<td><input TYPE="checkbox" NAME="org[7]" value="GRC">Globodera rostochiensis</input></td>
						</tr><tr>
							<td><input TYPE="checkbox" NAME="org[8]" value="HCC">Haemonchus contortus</input></td>
							<td><input TYPE="checkbox" NAME="org[9]" value="HGC">Heterodera glycines</input></td>
							<td><input TYPE="checkbox" NAME="org[10]" value="HSC">Heterodera schachtii</input></td>
							<td><input TYPE="checkbox" NAME="org[11]" value="LSC">Litomosoides sigmodontis</input></td>
						</tr>
						<tr height=20></tr>
					</table>
				</form>
			</td>
		</tr>
		<tr>
			<td>
				<form method="post" action="#"><!--form[1]-->
					<table width=100%>
						<tr>
							<td width=30%>						
								<div><div class="mainBig">Output by:</div>
									<label><input type="radio" name="out" value=0 /> table of clusters</label><br>
									<label><input TYPE="radio" NAME="out" VALUE=1 /> as SimiTri</label><br>
								</div>
							</td>
							<td valign=top>
								<div id="abun">
									<table width=100%>
										<tr>
											<td width=30%><div class="mainBig">Order results by</div></td>
											<td width=30%><div class="mainBig">Report</div></td>
										</tr>
										<tr>
											<td><input TYPE="radio" NAME="order" VALUE="0" checked>sequence abunance</td>
											<td><input TYPE="radio" NAME="hits" VALUE="0" checked>all hits</td>
										</tr>
										<tr>
											<td><input TYPE="radio" NAME="order" VALUE="1" >blast score</td>
											<td><input TYPE="radio" NAME="hits" VALUE="1">1st hit only</td>
										</tr>
									</table>
								</div>
								<div id="simi">
									<table width=100%>
										<tr><td><div class="mainBig">SimiTri data type</div></td></tr>
										<tr><td><input TYPE="radio" NAME="datatype" VALUE="0" checked>bit score</td></tr>
										<tr><td><input TYPE="radio" NAME="datatype" VALUE="1">expression</td></tr>
									</table>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</td>
		</tr>
		<tr height=20></tr>
		<tr>
			<td colspan=3 valign=top>
				<form method="post" action="test.php">
<!--					<input type="hidden" name="org" value=forms[0]>
						<input type="hidden" name="out" value="forms[1].out">-->
						<center><input TYPE="submit" VALUE="Search"></center>
				</form>
			</td>
		</tr>
	</table>
</body>
</html>

test.php
<?php
$orgs=$_POST['org'];   #read the org (organisms) array 
$output=$_POST['out'];  
 
$orgs2=array("a","b","c","d");
print "<!doctype html public \"-//w3c//dtd html 4.0 transitional//en\">";
print "<html>\n<head>\n</head>\n<body><br><center>";
print "output => $output <br> orgs=>    ";
print_r($orgs);
print "<br>testarray=>     ";
print_r($orgs2);
?>


#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 14 September 2006 - 01:22 PM

Why don't you just make it one big form ???

#3 ann

ann
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 14 September 2006 - 02:12 PM

becasue the javascript wont work! Well not for me but if anyone would like to tell me how to make it work on one form that would be great too.

The javascript for selecting output type is fine in one form but the "select all" button javascript requires an object called document.buttonDemo which I've difened in the form tag  <form method="post" name="buttonDemo">

So is there a way to defiine document.buttonDemo without using a form tag ?

#4 ann

ann
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 15 September 2006 - 01:49 PM

No solution but I've got to get on so I changed the button to a check box which means I can work the javascript in one form.

the code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
< script type="text/javascript"><!--
function checkAll(){
   for (i=0; i<document.forms[0].length; i++)
      if(document.forms[0].elements[i].name=="org[]") document.forms[0].elements[i].checked = true
}
function clearAll(){
   for (i=0; i<document.forms[0].length; i++)
      if(document.forms[0].elements[i].name=="org[]") document.forms[0].elements[i].checked = false
}//-->< /script>
</head>
<body>

<style type="text/css">	<!--.show {display:block;}.hide {display:none;}--></style>
< script type="text/javascript"><!--
	window.onload=function() {
		obj=document.getElementById('abun')
		obj.className='hide';
		objs=document.getElementById('simi')
		objs.className='hide';
		rad=document.getElementsByTagName('input');
		for(c=0;c<rad.length;c++) {
			if(rad[c].name=='out') {
				rad[c].onclick=function() {
					if(this.value==0) {obj.className='show';objs.className='hide';}
					else {obj.className='hide';objs.className='show';}
				}
			}
		}
	}
//-->< /script>

<form method="post" action="annotation_search.php">
<table class="tablephp2">
		<tr>
			<td>
				<table>
					<tr height=20></tr>
					<tr>
						<td><div class="mainBig">Species to search</div></td>
						<td>
							<input type=checkbox onClick="if(this.checked)checkAll(); else clearAll()"> sellect all
						</td>
					</tr>
					<tr height=20></tr>
					<tr>
						<td><input TYPE="checkbox" NAME="org[]" value="ACC">Ancylostoma caninum</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="ALC">Ascaris lumbricoides</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="ASC">Ascaris suum</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="AYC">Ancylostoma ceylanicum</input></td>
					</tr><tr>
						<td><input TYPE="checkbox" NAME="org[]" value="BMC">Brugia malayi</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="DIC">Dirofilaria immitis</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="GPC">Globodera pallida</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="GRC">Globodera rostochiensis</input></td>
					</tr><tr>
						<td><input TYPE="checkbox" NAME="org[]" value="HCC">Haemonchus contortus</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="HGC">Heterodera glycines</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="HSC">Heterodera schachtii</input></td>
						<td><input TYPE="checkbox" NAME="org[]" value="LSC">Litomosoides sigmodontis</input></td>
					</tr>
					<tr height=20></tr>
				</table>
				<table width=100%>
					<tr>
						<td width=30%>						
							<div><div class="mainBig">Output by:</div>
								<label><input type="radio" name="out" value=0 /> table of clusters</label><br>
								<label><input TYPE="radio" NAME="out" VALUE=1 /> as SimiTri</label><br>
							</div>
						</td>
						<td valign=top>
							<div id="abun"><table width=100%>
								<tr>
									<td width=30%><div class="mainBig">Order results by</div></td>
									<td width=30%><div class="mainBig">Report</div></td>
								</tr>
								<tr>
									<td><input TYPE="radio" NAME="order" VALUE="0" checked>sequence abunance</td>
									<td><input TYPE="radio" NAME="hits" VALUE="0" checked>all hits</td>
								</tr>
								<tr>
									<td><input TYPE="radio" NAME="order" VALUE="1" >blast score</td>
									<td><input TYPE="radio" NAME="hits" VALUE="1">1st hit only</td>
								</tr>
							</table></div>
							<div id="simi"><table width=100%>
								<tr><td><div class="mainBig">SimiTri data type</div></td></tr>
								<tr><td><input TYPE="radio" NAME="datatype" VALUE="0" checked>bit score</td></tr>
								<tr><td><input TYPE="radio" NAME="datatype" VALUE="1">expression</td></tr>
							</table></div>
						</td>
					</tr>
					<tr height=20></tr>
					<tr>
						<td colspan=3 valign=top>
							<center><input TYPE="submit" VALUE="Search"></center>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users