i did search the forum for this, but found no results.
i have a dynamic menu, when i select box a, it reloads screen and then fills in the items for box b.
i would like to rework it so that it does same job, onchange, not with a reload of page
[code=php]<?
if(isset($_GET[‘action’])){$action = $_GET[‘action’];
if($_GET[‘action’] == “add”){doAdd();}}
else {
if (isset($_GET[‘cat’])) {
$maincat = $_GET[‘cat’];
} else {
$maincat = ‘Select Category’;
}
echo ‘
<table align=”center” cols=”2″ border=”0″ width=”380″ cellpadding=”0″ cellspacing=”0″>
<form action=”item_add.php?action=add” method=”post” “enctype=”multipart/form-data>
<tr>
<td valign=”center” align=”right” colspan=”2″>
</td>
<tr>
<td valign=”center” align=”right” class=”me” width=”160″>
Main Category:
</td>
<td valign=”center” width=”220″ class=”me”>
<select name=”cat_a_val” onchange=”location = this.options[this.selectedIndex].value;”>
<option value=”‘.$maincat.'”>’.$maincat.'</option>
<option value=””> ————————- </option>’;
$query = mysql_query(“SELECT ID, title from item_cat_a ORDER by title”) or die(mysql_error());
while ($row = mysql_fetch_assoc($query)){
echo ‘
<option value=”./item_add.php?cat=’.stripslashes($row[‘title’]).'”>’.stripslashes($row[‘title’]).'</option>
‘;
}
echo ‘ </select>
</td>
</tr>
<tr>
<td valign=”center” align=”right” class=”me” width=”160″>
<br />Sub Category:
</td>
<td valign=”center” width=”220″ class=”me”>
<br /><select name=”cat_b_val”>
<option value=””>Select sub-category</option>
<option value=””> —————————— </option>’;
$queryb = mysql_query(‘SELECT * FROM item_cat_b WHERE cat_a_val = ”.$maincat.” ORDER BY title’) or die(mysql_error());
while ($rowb = mysql_fetch_assoc($queryb)){
echo ‘
<option value=”‘.stripslashes($rowb[‘title’]).'”>’.stripslashes($rowb[‘title’]).'</option>
‘;
}
echo ‘ </select>
</td>
</tr> <tr>
<td valign=”center” align=”right” class=”me” width=”160″>
<br />Item Name:
</td>
<td valign=”center” width=”220″ class=”me”>
<br /><input type=”text” size=”25″ name=”title”>
</td>
</tr>
</table>
‘;
}
function doAdd(){
$_POST[‘title’] = addslashes($_POST[‘title’]);
$query = mysql_query(“INSERT INTO item_all VALUES(”, ‘$_POST[cat_a_val]’, ‘$_POST[cat_b_val]’, ‘$_POST[title]’)”) or die(mysql_error());
header(“Location: manage_item.php”);
}
?>
like i said, i would like to do this without the javascript reload, and instead with a onchange value