/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with JavaScript and PHP

Hi, I have a script which allows the user to choose an animal from a drop down menu, and then changes an image on the page based on what animal they chose

[CODE]<script type=”text/javascript”>
$(function() {
$(‘select’).change(function() {
var val = $(this).val();
if(val == “”){
document.getElementById(‘Image’).innerHTML = “”;
}else{
var Image = ‘<img id=”Image” src=”Images\’+val+’.png” />’;
document.getElementById(‘Image’).innerHTML = Image;
}
});
});
</script>
<select>
<option value=””>Choose an animal</option>
<option value=”Cat”>Cat</option>
<option value=”Dog”>Dog</option>
<option value=”CatDog”>CatDog</option>
</select>
<div id=”Image”></div>[/CODE]

This is working fine for me, however, i now want to make it so that when the user picks an option from the menu, the rest of the page is then updated with information which is fetched from a database. I know that PHP and JavaScript work in very different ways, but I need a way to pass the variable from the JavaScript containing the option that they selected to a PHP variable, that i can use within an SQL statement, but am really struggling with how I can do this, any help much appreciated.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@touch_the_sky1Nov 06.2011 — What you are looking for is [B]Ajax[/B]
Copy linkTweet thisAlerts:
@SamB123authorNov 06.2011 — Hmm, I've heard of Ajax, no experience in it though, could you point me to somewhere where i could find some that would be of use to me? ?
Copy linkTweet thisAlerts:
@SamB123authorNov 06.2011 — Nevermind, after a bit of digging round i've solved it, thankyou ?
×

Success!

Help @SamB123 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.19,
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,
)...