Hai all, im new here so plz help me..im doing a php progrm so i try to passing the first jump menu to the second one on the same page..i tru using onchange but noting happen....both of the selction using data from sql data base..so plz help me
this is the code..

<?php session_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="userdb"; // Database name
$tbl_name="logindb"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


?>

<!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">
<link type="text/css" rel="stylesheet" href="/FileSystem/FS.css">
<style type="text/css">
<!--
.style4 {font-size: 24px}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link type="text/css" rel="stylesheet" href="/FileSystem/FS.css">

<title>Msg</title>

</head>

<body bgcolor="#0066FF">


No Fail :
           <?php
		   
		   echo "<form method='get'> ";
 				$sqlfile = "SELECT * FROM filedb ;";
				$result = mysql_query($sqlfile) or exit("QUERY FAILED!");
				echo "<select name='menu2' onchange='MM_jumpMenu(parent,this,0)'>";
				while ($rf=mysql_fetch_array($result)) {
				echo "<option value='$rf[0]'>".$rf[0]."</option>";}			  
                
				
				echo "</select></form>";
?><span class="style7">*</span>
  <?php 
           
 				$sql2 = "SELECT AttNO FROM attdb WHERE fileID= '".$_GET['menu2']."';";
				$result2 = mysql_query($sql2) or exit("QUERY FAILED!");
				echo "<select name='menu1' onchange='MM_jumpMenu(parent,this,0)'>";
				while ($rt=mysql_fetch_array($result2)) {
				echo "<option value='$rt[0]'>".$rt[0]."</option>";}			
                echo "</select>";
?><span class="style7">*</span>
</body>
</html>

Hi there, I think that the problem may lie in your javascript, try changing the parameter of the eval() function to:

targ+".location='"+selObj.options[selObj.[B]options[/B].selectedIndex].value+"'"

Tq,
so How i transfer the first value of jump menu to the second one using php?

Hi, first create Table

CREATE TABLE IF NOT EXISTS `table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ItemCode` varchar(100) NOT NULL,
  `ItemName` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `table`
--

INSERT INTO `table` (`id`, `ItemCode`, `ItemName`) VALUES
(1, 'it1', 'shop'),
(2, 'it2', 'music');

and a php page subcat.php

<? 
mysql_connect('localhost', 'root', '') ;
mysql_select_db('new'); 

if($_SERVER['REQUEST_METHOD']=="POST")
{
$item="Insert into `anothertable`(`id`,`ItemCode`,`ItemName`) values('','".$_POST['selcategory']."','".$_POST['selsubcat']."')";
$query=mysql_query($item);
header("location:subcat.php?msg=ad");

}

$cres=mysql_query("select * from `table`");
$ccunt=mysql_num_rows($cres);
	echo "<script language=javascript>\n";
	echo "function getsubcats() {\n";
		echo "var d=document.f1;\n";
		echo "if(d.selcategory.value==0) {\n";
			echo "d.selsubcat.options.length = 0;\n";
			echo "d.selsubcat.options[0]=new Option(\"Select Subcategory\",\"\")\n";
		echo "}\n";
	while($row_cat=mysql_fetch_array($cres,MYSQL_BOTH)){
		echo "if(d.selcategory.value==".$row_cat['id'].") {\n";
				echo "d.selsubcat.length=0;\n";
				$sub_res=mysql_query("select * from `table` WHERE ItemCode='".$row_cat['ItemCode']."'");  
				$i=1;
				echo "d.selsubcat.options[0]=new Option(\"Select Subcategory \",\"\")\n";
				while($sub_row=mysql_fetch_array($sub_res,MYSQL_BOTH)){
					echo "d.selsubcat .options[".$i."]=new Option('".$sub_row['ItemName']."','".$sub_row['ItemName']."');\n";
					$i=$i+1;
				}   
		echo "}\n";
	}  
	echo "}</script>\n"; 


?>


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <form name="f1" method="post" action="">
  <tr>
    <td colspan="3" align="center"><? if(!empty($_GET['msg'])) { echo "Record Added successfully";}?></td>
    </tr>
  <tr>
    <td width="33%">Item code </td>
    <td width="3%">&nbsp;</td>
    <td width="64%"><select name='selcategory' id='selcategory' onchange="return getsubcats();">
       <option value='0'>----select item code---</option>
	  <? $sel="select * from `table`";
	  $qry=mysql_query($sel);
	  while($fet=mysql_fetch_assoc($qry)) {?>
	  
	  <option value='<? echo $fet['id']?>'><? echo $fet['ItemCode']?></option>
	  <? }?>
    </select></td>
  </tr>
  <tr>
    <td>item name </td>
    <td>&nbsp;</td>
    <td><select name='selsubcat' id='selsubcat'>
      <option value='0'>----select item name---</option>
    </select></td>
  </tr>
  <tr>
    <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit" /></td>
  </tr></form>
</table>
</body>
</html>

Hope this will help u. Its dynaimc drop down. make this thread solved.

tq ayesha789 that maybe little helpful
..but the the reason i wrote this threat asking how i cam get the value of the first jump menu

<?php
		   
		   echo "<form method='get'> ";
 				$sqlfile = "SELECT * FROM filedb ;";
				$result = mysql_query($sqlfile) or exit("QUERY FAILED!");
				echo "<select name='menu2' onchange='MM_jumpMenu(parent,this,0)'>";
				while ($rf=mysql_fetch_array($result)) {
				echo "<option value='$rf[0]'>".$rf[0]."</option>";}			  
                
				
				echo "</select></form>";
?>

and put it inside the sql2 command

<?php 
           
 				$sql2 = "SELECT AttNO FROM attdb WHERE fileID= '".$_GET['menu2']."';";
				$result2 = mysql_query($sql2) or exit("QUERY FAILED!");
				echo "<select name='menu1' onchange='MM_jumpMenu(parent,this,0)'>";
				while ($rt=mysql_fetch_array($result2)) {
				echo "<option value='$rt[0]'>".$rt[0]."</option>";}			
                echo "</select>";
?>

without to go to the next page,
i stdy that they use onchange but i cant get the value and pass it

If I understand what you are doing, it seems you are trying to call PHP scripts with a JavaScript function, this will not work without either:
1. Reloading the page
2. Implementing an AJAX type script to make a call to the PHP script.

There are plenty of guides online on creating AJAX scripts. This would probably be the best option for what you want to do.

This article has been dead for over six months. Start a new discussion instead.