Linked combo boxes action required

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Linked combo boxes action required

Post 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();
?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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">
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Post by wasir »

Thanks for your help but that doesn't work.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please elaborate on "doesn't work"
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Post by wasir »

Nothing happens on pressing SUBMIT button.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Post 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" />
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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")
Post Reply