SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is it possible to run PHP code inside a JavaScript function?

    Hello again, I wonder if anyone could help?

    I have a page where a select box is dynamically generated with PHP. I need to make it so when the user selects something and moves onto the next input control, some PHP needs to be run to call up a database, take the selected data from the select box and run a query. Then spurt out some data back from the database into the next input control automatically.

    I've got the select box populated fine, and I'm using onblur="fill_complete(this);" to trigger off a javascript function (called fill_complete()) that would then need to run the PHP to make a database call.

    How could I do this? I'm confused...

    Hope you can help me!

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... I wonder... Is this where AJAX comes in to the picture? Is there an alternative way of doing it without using AJAX, or is that the only option to do this type of thing properly?

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by littlejim84 View Post
    ... I wonder... Is this where AJAX comes in to the picture? Is there an alternative way of doing it without using AJAX, or is that the only option to do this type of thing properly?
    Other option is to reload the page when the dropdown value changes. Use the onchange event to achieve this.

  5. #5
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for replying... I don't know nothing about AJAX, weren't sure if this was something where AJAX would come in useful...

    So aside from using AJAX, the only other option is to reload the page again? Hmm... That's not really an option.

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will then have to learn how to use Ajax. There are tons of tutorials out there. See the link above.

  7. #7
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, thanks buddy. I'm up for the challenge of learning Ajax... I just wanted to make sure 100% there wasn't another way around it...

  8. #8
    SitePoint Addict
    Join Date
    Jul 2006
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ajax and dropdown

    If you figure it out please give example code. I had a similar proplem around a year ago. I believe what you are after is similar to doing a database lookup. I.E., like selecting a customer from a dropdown then having the ship address, phone and other fields auto filled. dhtmgooddies has an example, but not using a dropdown. I actually understand their example, but never figured how to do the same from a dropdown based on a database. I went with just reloading page, does it just as fast with high speed. I know fedex fills fields after a dropdown selection.


Bookmarks

Posting Permissions

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