/    Sign up×
Community /Pin to ProfileBookmark

multiple dynamic dropdown, works on reload, would like onchange

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: &nbsp;
</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: &nbsp;
</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: &nbsp;
</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”);
}

?>[/code]

like i said, i would like to do this without the javascript reload, and instead with a onchange value

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @kender spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...