SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to load a file when a button is clicked?

    Hello,

    I don't know much about javascript so this may be an obvious question or one that's impossible, but...

    I want to have a button (in the middle of another form) that, when clicked, downloads a URL and shows the content to the user.) (Well it's okay if it doesn't download the page... I just want the request sent.)

    Basically I want a button that resets a field in a SQL database (I have a PHP script to do it) and I want to have it done w/out displaying another webpage. I was thinking maybe loading a new .js file (which would be my php script is disguise) when the button is clicked, but I can't figure out how to do that either.

    Owen

  2. #2
    SitePoint Zealot jonsteele's Avatar
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Owen,

    You can use the "php server call in a virtual js image" trick (I made that name up ).

    Basically you set the source of an image (via javascript) to the php page you want, sending any query string variables along with the url. This will cause the server to process the script without the page being reloaded. However, no variable can be sent back from the server without a refresh (if someone can prove me wong I will be greatly in your debt!)

    Code:
    <script language="JavaScript">
    myImg = new Image();
    myImg.src = "myAwesomePHPscript.php?variable=value";
    </script>
    Jon


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
  •