Results 1 to 4 of 4

Thread: [RESOLVED] Help with JavaScript and PHP

  1. #1
    Join Date
    Oct 2011

    resolved [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
    <script type="text/javascript">
    $(function() {
        $('select').change(function() {
            var val = $(this).val();
    		if(val == ""){
    		document.getElementById('Image').innerHTML = "";	
    		var Image = '<img id="Image" src="Images\\'+val+'.png" />';
            document.getElementById('Image').innerHTML = Image;
    <option value="">Choose an animal</option>
    <option value="Cat">Cat</option>
    <option value="Dog">Dog</option>
    <option value="CatDog">CatDog</option>
    <div id="Image"></div>
    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.

  2. #2

  3. #3
    Join Date
    Oct 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?

  4. #4
    Join Date
    Oct 2011


    Nevermind, after a bit of digging round i've solved it, thankyou

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center