Page 1 of 1

Linked combo boxes action required

Posted: Thu Aug 30, 2007 2:07 am
by wasir
I am using linked combo boxes connected to DB, which is working all fine but I don't know how to get the SUBMIT button working...

I need to send the value of ['sno'] from $result2 to process.php

:?: :?: :?: :?:

Code: Select all

<?php
include ('functions_new.php5');
echo getHeaderCrown();

if (!isset($passed_value)){ $passed_value=1;}
if (!isset($passed_value2)){ $passed_value2=1;}

?>

<body onload="redirect(<?php echo $passed_value.','.$passed_value2?>,2)">

	<?php 
	include('con.php');
	$sql="select * from categories";
	$sql2="select * from subcategories WHERE categ=".$passed_value;
	$result=mysql_query($sql,$id_link) or die (mysql_error());
	$result2=mysql_query($sql2,$id_link) or die (mysql_error());
	?>
			
	<form name="doublecombo">

	<label for="example">Select the CATEGORY here:</label>
	<select id="example" name="example" size="1"  onChange="redirect(this.options.selectedIndex,<?php echo $passed_value.','.$passed_value2?>)">
	<option>-select-</option>

	<?php
  		while ($newarray=mysql_fetch_array($result)) {
		    echo '<option value="'.$newarray['sno'].'" ';
			if ($newarray['sno']==$passed_value) {echo "SELECTED";};
			echo '>'.$newarray['categories'].'</option>'.'\n';
	  	} 
	?> 

	</select>

	<label for="stage2">Select the SUB-CATEGORY here:</label>
	<select id="stage2" name="stage2" size="1">

	<?php 
		while ($newarray=mysql_fetch_array($result2)) {	
		    echo '<option value="'.$newarray['sno'].'" ';
			if ($newarray['sno']==$passed_value2) {echo "SELECTED";};
			echo '>'.$newarray['scategories'].'</option>';
		    $x=$x+1;} 
	?>

	</select>


	<input type="button" name="test" value="Submit" onClick="go()" />

	<script>
	<!--
	/*
	The original JScript can be found in nearly every JScript website
	I'm just mentioning one 
	Courtesy of SimplytheBest.net - http://simplythebest.net
	*/
	var groups=document.doublecombo.example.options.length
	var group=new Array(groups)
	for (i=0; i<groups; i++){
	group[i]=new Array
	
	}
	<?php 
	//Here comes the data from the two linked tables in a format suited for JScripting
	// into the script mentioned here above
	
	$sql="select * from categories";
	
	$result=mysql_query($sql,$id_link) or die (mysql_error());
	$x=0;$y=0;$m=0;$z=1;
	
	 while ($newarray=mysql_fetch_array($result)) { 
		echo "group[0][$m]=new Option(\"".$newarray['categories'].'","'.$newarray['sno'].'")'."\n";
		$sql2="select * from subcategories WHERE categ=".$newarray['sno']." order by sno asc";
		$result2=mysql_query($sql2,$id_link) or die (mysql_error());
		
		while ($newarray2=mysql_fetch_array($result2)) {
			echo "group[$z][$y]=new Option(\"".$newarray2['scategories'].'","'.$newarray2['sno'].'")'."\n";
			$y=$y+1;
			
			}
		$z=$z+1;
		$y=0;
		$m=$m+1;
		}
	?>
	
	
	var temp=document.doublecombo.stage2
	function redirect(x,d,f){
	
	for (m=temp.options.length-1;m>0;m--)
	
	temp.options[m]=null
	
	for (i=0;i<group[x].length;i++){
	temp.options[i]=new Option(group[eval(x)][i].text,group[eval(x)][i].value)
	}
	temp.options[d].selected=true
	
	}
	
	//-->
	</script>

	</form>

<?php	
echo getFooter();
?>

Posted: Thu Aug 30, 2007 2:33 am
by s.dot
When you hit the submit button, all your info should be available in $_POST on process.php

EDIT| It'd also help if you put that info in the form tag :)

Change this:

Code: Select all

<form name="doublecombo">
To this:

Code: Select all

<form name="doublecombo" action="process.php" method="post">

Posted: Thu Aug 30, 2007 6:57 am
by wasir
Thanks for your help but that doesn't work.

Posted: Thu Aug 30, 2007 7:40 am
by volka
please elaborate on "doesn't work"

Posted: Thu Aug 30, 2007 8:03 pm
by wasir
Nothing happens on pressing SUBMIT button.

Posted: Thu Aug 30, 2007 8:44 pm
by CoderGoblin
wasir wrote:I am using linked combo boxes connected to DB, which is working all fine but I don't know how to get the SUBMIT button working.
Are you saying the combo boxes work as expected already but once they are completed you cannot get the "next" page to process ?

If so I would guess this is because you do not have a javascript function go().

Code: Select all

<input type="button" name="test" value="Submit" onClick="go()" />
Remove the onClick.

Posted: Thu Aug 30, 2007 9:41 pm
by wasir
Thanks for your help. It's working fine by changing

Code: Select all

<input type="button" name="test" value="Submit" onClick="go()" />
to

Code: Select all

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

Posted: Thu Aug 30, 2007 10:00 pm
by CoderGoblin
Pleased I could help. Just as a point of interest I have had problems before giving a submit button the name "submit". It caused javascript to be confused but cannot remember what the precise problem was. You my want to call it something different (I often use "doit")