/    Sign up×
Community /Pin to ProfileBookmark

changing variable locally to update drop downs using onchange

I have a footer with 3 menus. Each are dependent. Make, Model, and Year.

When user selects make (onchange event) model updates.
When user selects Model (onchange event) year updates.

Once the user has selected Make, model, and Year and submits it using the submit button it will go to the form and update the actual listings.

Any help would be awesome!

Right now its setup that onchange submits the new url which changes the listings being viewed. But does update the list menus. I want just the list menus to update.

[code=php]

<form name=”filter_form” method=”get” action=”search_filter.php” id=”footer_sub”>

<ul id=”searchfilter”><li>

<select id=”make” name=”make” onchange=”location.href=’search_filter.php?make=’+filter_form.make.options[selectedIndex].value+’&userZip=<?php echo $userZip; ?>&model=model_all&year=year_all&distance=<?php echo $distance; ?>'”>

<?php

if (isset($_GET[‘make’])) {

$result=mysql_query(“SELECT DISTINCT make FROM listings order by make”) or die(mysql_error());

while($query_data = mysql_fetch_assoc($result)) {
$mk = $query_data[‘make’];
//if a make was selected and matches the one in the qry row,
//set the option’s selected attribute
$selected = ($_GET[‘make’] == $mk) ? ‘ selected=”selected”‘ : ”;
echo “<option value=”$mk”$selected>$mk</option>”;
}
}

?>

</select>
</li><!–END OF MAKE–>

<li><select id=”model” name=”model” >
<option selected=”selected” value=”model_all” onchange=”location.href=’search_filter.php?make=<?php echo $make; ?>&userZip=<?php echo $userZip; ?>&model=’+filter_form.model.options[selectedIndex].value+’&year=year_all&distance=<?php echo $distance; ?>'”>All Models</option>

<?php

if (isset($_GET[‘make’])) {

$result = mysql_query(“SELECT DISTINCT model FROM listings WHERE make =’$make’ ORDER BY model”) or die(mysql_error());

while($query_data = mysql_fetch_assoc($result)) {
$md = $query_data[‘model’];
//if a make was selected and matches the one in the qry row,
//set the option’s selected attribute
$selected = ($_GET[‘model’] == $md) ? ‘ selected=”selected”‘ : ”;
echo “<option value=”$md”$selected>$md</option>”;
}
}
?>

</select>
</li><!–END OF MODEL–>

<li><select id=”year” name=”year”>

<option selected=”selected” value=”year_all”>All Years</option>

<?php

if ($_GET[‘model’] == “model_all” ) {

$result = mysql_query(“SELECT DISTINCT year FROM listings WHERE make =’$make’ ORDER BY year DESC”) or die(mysql_error());

}

if ($_GET[‘model’] != “model_all” ) {

$result = mysql_query(“SELECT DISTINCT year FROM listings WHERE make =’$make’ and model =’$model’ ORDER BY year DESC”) or die(mysql_error());

}

while($query_data = mysql_fetch_assoc($result)) {
$yr = $query_data[‘year’];
//if a make was selected and matches the one in the qry row,
//set the option’s selected attribute
$selected = ($_GET[‘year’] == $yr) ? ‘ selected=”selected”‘ : ”;
echo “<option value=”$yr”$selected>$yr</option>”;
}

?>
</select><!–END OF YEAR–>
</li>

<li>
<input value=”submit” type=”submit”/>
</li>
</ul>
</form>[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @buildingbrick 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 4.28,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...