SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 32 of 32
  1. #26
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure.

    A link in filename.php opens up popup.php that contains a form.

    On submitting this form, a database is updated with the contents of the form (no problem there) and after a few seconds (to allow the database to update) filename.php is refreshed.

    The timeout only works when the form doesn't submit. The refresh works when the form submits, but only when the timeout isn't there.

    I tried using a button and submitting the button with code in the function, but it was temperamental at best. Sometimes it didn't refresh at all, usually the first time the form was submitted.

    Is this really wierd?

  2. #27
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,420
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    settimeout

    I threw together these 3 files
    filename.html
    HTML Code:
    <html><head><title>filename.html</title>
    </head>
    <body>
    <form>
    <input type="text" value="change to see if refreshed">
    <input type="button" onclick="window.open('popup.html', 'popup', '');" value="open pop-up">
    </form>
    </body></html>
    popup.html
    HTML Code:
    <html><head><title>popup.html</title>
    <script type="text/javascript">
    function reloadOpener(){
    	alert("in reloadOpener");
    	setTimeout("doItNow()",2000);
    	return;
    }
    function doItNow(){
    	alert("in doItNow");
    	window.opener.location.reload();
    	var the_form = document.getElementById("the_form");
    	the_form.submit();
    }
    </script>
    </head>
    <body>
    <form id="the_form" name="the_form" action="submitted.html" method="post">
    <input type="submit" id="submit_button"
    name="submit_button" value="Submit" class="input"
    onclick="reloadOpener(); return false;" />
    </form>
    </body></html>
    submitted.html
    HTML Code:
    <html><head><title>submitted.html</title>
    </head>
    <body>
    submitted
    </body></html>
    They work as expected in IE6 for me (filename gets reloaded and form submits).

  3. #28
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Had a go at that. Unsuccesful I'm afraid. The form in popup.html is updating a database. I want the form to submit, update the database, then a few seconds later the opener reloads, reflecting the changes made to the database.

    So I modified your script slightly by putting the code for the form submission inside the reloadOpener() function. The form submitted as expected, and the database was updated, but once again, the doItNow() function just didn't happen. When I removed the setTimeout it did happen.

    It's the same every time. No matter what way I try this, the setTimeout function stops doItNow() happening if the form has been submitted. Without setTimeout doItNow() works properly and the opener reloads. What can this issue be?? . Very effin

  4. #29
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This doesn't give me much hope.

    http://jboss.solidwebhosting.net/jbo...ree-web-space/

    He hinted that increasing the length of the timeout could be a (blunt) solution, but that doesn't work either. I set it to 10 seconds, the form submitted in about 0.5, I waited 30, nothing happened.

    Is there no such thing as doNothing(5000); !?!?

  5. #30
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,420
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    do nothing

    You could do a sleep() server-side with PHP, but if the settimeout isn't working, the only thing I can think of is to use something to take up time. Generally not wise, but maybe neccessary here (for who knows what reason). eg
    HTML Code:
    for (var i = 0; i < 100; i++){
       for (var j = 0; j < 100; j++) {
          for (var k  = 0; k < 100; k++) {
             var m = 1;
          }
       }
    }

  6. #31
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's fixed! . Very effin

    I put this:

    HTML Code:
    ?>
    <script language="JavaScript" type="text/javascript">
    <!--
    window.opener.location.reload();
    //-->
    </script>
    <?php
    after the php code that updates the database. It's worked 30 times in a row, and that's good enough for me.

    Now I would like to express a big thank you to Mittineague who has patiently sat through this one with me. I have probably been the cause of one or two definitely a and I would imagine lots of when he has looked at how I stumble through javascript.

    So thank you.

  7. #32
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,420
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    solved!

    Great!
    No problem. I still stumble along quite often myself. Usually with "new" stuff, but once and a while something simple that I overlook. One thing I have found however, is that if you're persistant long enough, 99.99&#37; of the time you'll figure it out.


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
  •