Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Simple Image Display On Click

  1. #1
    Join Date
    Mar 2006
    Location
    Buffalo, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Simple Image Display On Click

    Hello everyone!

    I am new to this DHTML concept. I have been programming in PHP for years, using the basic HTML, CSS and JavaScript concepts everyone uses (tables, rollover images, underline links on rollover, scrollbar effects, etc.). However after checking out dynamicdrive.com I was truly intrigued at how powerful and useful this DHTMLstuff can be.

    I have a form that is submitted to a PHP scripted page on a button click. I was wondering if I could have the button "SAVE And Exit" become disabled and have the value of the button change to "Please wait..." upon the user clicking it.

    I also wanted to have an image display below the button "Please wait.." after the user clicks the "SAVE And Exit" button, this image would be a loading bar that I have created (animated gif image). The reason for this is after the user clicks "SAVE And Exit" they are uploading 20 photos which take PHP time to upload, to this "Please wait.." button text and loader image would appear until PHP finished and the next process in PHP I have programmed would continue. I saw that dynamicdrive.com had loader bars, but thats really not what I am looking for, like I said something really simple.

    I have looked through your scripts on your site and found scripts that perform the action I am looking for, but they are really more than what I need (they allow show/hide; I only want show and disable). Once again I am looking for something very simple.

    Suggestions Welcomed!!!
    Last edited by icesolid; 03-02-2006 at 04:33 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <input id="upload" type="submit" value="Save &amp; Exit" onclick="setLoading(true)" />
    <img src="loaderImage.png" style="visibility:hidden;" id="loader" />
    
    <script type="text/javascript">
    var uploadButtonId = "upload",
      loaderImageId = "loader";
    
    function setLoading(yes) {
      var seal = document.getElementById(uploadButtonId),
        baskingShark = document.getElementById(loaderImageId);
    
      seal.value = yes ? "Please wait..." : "Save & Exit";
      seal.disabled = yes;
    
      baskingShark.style.visible = yes;
    }
    </script>
    setLoading(true) to enable the loader; setLoading(false) to disable it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Location
    Buffalo, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Not Working

    Using the code posted above the Save & Exit text changes and the button is disabled, however the image does not show up. I did rename the image to the image on my directory.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, you're right, I made a stupid error.
    Code:
    <input id="upload" type="submit" value="Save &amp; Exit" onclick="setLoading(true)" />
    <img src="loaderImage.png" style="visibility:hidden;" id="loader" />
    
    <script type="text/javascript">
    var uploadButtonId = "upload",
      loaderImageId = "loader";
    
    function setLoading(yes) {
      var seal = document.getElementById(uploadButtonId),
        baskingShark = document.getElementById(loaderImageId);
    
      seal.value = yes ? "Please wait..." : "Save & Exit";
      seal.disabled = yes;
    
      baskingShark.style.visibility = yes ? "visible" : "hidden";
    }
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Buffalo, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This code works great, only draw back is that it doesen't actually submit to the page defined in the <form> tag. It just stays at the page with the loader image.

    My <form> tag:

    <form method="post" action="upload.php">

    Anyone?
    Last edited by icesolid; 03-02-2006 at 08:19 PM.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Remove the onclick from the submit button, and put
    Code:
    onsubmit="setLoading(true);return true;"
    in the form tag.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Location
    Buffalo, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That worked, but now none of the values in the form are submitted?

    For example: $_POST["save"] is not recognized in PHP as being submitted.

  8. #8
    Join Date
    Mar 2006
    Location
    Buffalo, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anyone with any ideas of why when the form is submitted I loose all of my form values?

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Really? Well, that's odd... did you specify method="post" in your form tag?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Buffalo, NY
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yup, sure did.

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
  •