can't get the value from the first combobox. how should I do

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
gpong
Forum Newbie
Posts: 16
Joined: Sun Aug 06, 2006 8:49 am

can't get the value from the first combobox. how should I do

Post by gpong »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi
I have a problem with my php. I have 2 combo box, the first combobox i fill with table name from database and the second combobox i want to fill it with field from table that i picked from first combobox. the problem is i can't get the value from the first combobox. how should I do?? javascript is needed,isn't it? 

here is my code:

Code: Select all

<?
require "Plugins/config.inc.php";
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>&#28961;&#27161;&#38988;&#25991;&#20214;</title>
<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>

<body>
<?
    
	$DBname=$_GET['DBname'];
?>
<table width="766" height="245" border="0">
<form id="form1" name="form1" method="post" action="updateDB.php">
  <tr>
    <td width="65" height="42">Table:</td>
    <td width="20">
        <input name="table" type="radio" value="1" />      </td>
    <td width="144"><select name="menu2" onChange="MM_jumpMenu('parent',this,0)">
<?
	$str="show tables from $DBname";
	$query=mysql_query($str) or die(mysql_error());
	while(list($table)=mysql_fetch_row($query))
	{
		echo "<option value="InsertData.php?DBname=$DBname">$table</option>";
	}
?>
	  
    </select></td>
    <td width="22">
     
        <input name="table" type="radio" value="2" />    </td>
    <td width="157">
        <input type="text" name="tablename" />      </td>
    <td colspan="2">
        <input name="table" type="radio" value="3" />
      
    ALL      </td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td height="40">Field:</td>
    <td>&nbsp;</td>
    <td><select name="menu3" onChange="MM_jumpMenu('In',this,0)">
      <option>&#26410;&#21629;&#21517;1</option>
    </select></td>
    <td>&nbsp;</td>
    <td><input type="text" name="textfield2" /></td>
    <td colspan="2">
        <input type="text" name="textfield3" />      </td>
    <td colspan="2"></td>
  </tr>
  <tr>
    <td>Action:</td>
    <td>
        <input name="radiobutton" type="radio" value="radiobutton" />      </td>
    <td>Clear</td>
    <td>
        <input name="radiobutton" type="radio" value="radiobutton" />      </td>
    <td>Delete</td>
    <td width="25">
        <input name="radiobutton" type="radio" value="radiobutton" />      </td>
    <td width="129">Update</td>
    <td width="22">
        <input name="radiobutton" type="radio" value="radiobutton" />      </td>
    <td width="144">Insert</td>
  </tr>
  
  <tr>
    <td>Value:</td>
    <td>
        <input name="radiobutton" type="radio" value="radiobutton" />      </td>
    <td>
        <input type="text" name="textfield4" />    </td>
    <td>
        <input name="radiobutton" type="radio" value="radiobutton" />    </td>
    <td>NewID</td>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td colspan="9">
        <input type="submit" name="Submit" value="&#36865;&#20986;" />
  </form>
    
</table>

</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]
Last edited by gpong on Wed Aug 15, 2007 10:46 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Please update this thread's subject to be more descriptive, immediately.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: can't get the value from the first combobox. how should

Post by superdezign »

gpong wrote:I have a problem with my php. I have 2 combo box, the first combobox i fill with table name from database and the second combobox i want to fill it with field from table that i picked from first combobox. the problem is i can't get the value from the first combobox. how should I do?? javascript is needed,isn't it?
Depends on where the change happens. If you select from the first box, press submit, and then the second, you can do it all server side using the posted data. However, if you do it live on the page, you'll need more than just JavaScript to get the valid tables... You'll need to use AJAX.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Dynamic/Chained Selects using Ajax Prototype/JQuery does what I think you are after with javascript using one of two possible javascript libraries available (more libraries are easily available on the web). If you read the entire thread it also goes into examples of how to allow for if the user does not have javascript enabled.
Post Reply