Page 1 of 1

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

Posted: Wed Aug 15, 2007 10:15 pm
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]

Posted: Wed Aug 15, 2007 10:21 pm
by feyd
Please update this thread's subject to be more descriptive, immediately.

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

Posted: Thu Aug 16, 2007 5:41 am
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.

Posted: Thu Aug 16, 2007 6:12 am
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.