/    Sign up×
Community /Pin to ProfileBookmark

I want to change select value samilar to other select value

Hello
I want to change <select> values samiler to other select value
for example
I choise honda from <select id=”car”> got new values in <select id=”model”> 1) civic 2) accord 3) … etc
and these models in database
here my code

[code=html]
<head>
<script
src=”//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”>
</script>
<script type=”text/javascript”>
$(document).ready(function() {

$(“#make”).change(function() {
var val = $(this).val();

<?php
$result = mysqli_query($americacon,”SELECT * FROM cars WHERE make = val”);
while($row = mysqli_fetch_array($result)) {
?>
$(“#model”).html(“<option value='<?php echo $row[‘model’]; ?>’><?php echo $row[‘model’]; ?></option>”);
<?php
}
?>
});
</script>
</head>
<body>
<select id=”make”>
<option value=”honda”>honda</option>
<option value=”golf”>Golf</option>
</select>
<select id=”model”>
<option></option
</select>
</body>

[/code]

sorry for my english

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JCPerezAug 22.2014 — I recomend you to use [B]ajax[/B] to get data from a database... You can not pass info or variables from [B]js[/B] to [B]php[/B] as you did. Var [B]val[/B] does not exist when you do the query.
×

Success!

Help @emadiga 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.20,
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,
)...