Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-29-2012, 03:00 AM   PM User | #16
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Quote:
Originally Posted by Old Pedant View Post
Which code isn't working in FF? Exactly what is in your post #11 or something different?
I'll get you the code. Firefox is reloading the page. You can see it here: http://www.QuizBonanza.com/campaigns/iframe.php


Code:
<iframe id="myframe" width=100% height=1000px></iframe> 

<form name="this_form" method="POST" action="">
    <input type="submit" name="submit4" value="Submit" onclick="loadNextPage(1)"></button>
</form>
<?
$link = mysql_connect('localhost', 'ad20_ad20', 'xxxxxxxx');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('xxxxxxx', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
?>
<script type="text/javascript">
      var cnt=0,webpageArray = [<?php
$query = "SELECT URL FROM path where campaigns LIKE '%$currentFile%'";
$result = mysql_query($query) or die( mysql_error() );
$delimiter = "";
while ( $row = mysql_fetch_array($result) )
{
    echo $delimiter . '"' . $row[0]. 'UNIQUEID' . '"' ;
    $delimiter = ",\n";
}
?>]; 
      var countDown;

      function doCountDown( )
      {
          var btn = document.this_form.submit4;
          if ( countDown <= 0 )
          {
              btn.value = "Submit";
              btn.disabled = false;
              return;
         }
         btn.value = "Submit... " + countDown;
         btn.disabled = true;
         --countDown; 
         setTimeout( doCountDown, 1000 );
    }

    function loadNextPage(dir) {   
        cnt += dir;
        // this can never happen: if (cnt<0) cnt=webpageArray.length-1; // wrap
        
        if (cnt>= webpageArray.length) {
            return;
        } 
        var iframe = document.getElementById("myframe"); 
        iframe.src = webpageArray[cnt]; 
        countDown = 10;
        doCountDown( );
$('html, body').animate({ scrollTop: 0 }, 'fast');
    } 
    loadNextPage(0); // actually loads first page
</script>

Last edited by markman641; 10-29-2012 at 03:15 AM..
markman641 is offline   Reply With Quote
Old 10-30-2012, 02:17 AM   PM User | #17
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You messed up.

Code:
<form name="this_form" method="POST" action="">
<input type="submit" name="submit4" value="Submit" onclick="loadNextPage(1)"></button>
</form>
First of all, that is ILLEGAL HTML. So who knows what the various browsers will do with illegal html?

You have a </button> tag but *NO* matching <button> tag.

But more than that...

Because that button is a SUBMIT BUTTON, when the loadNextPage function returns, the button GOES AHEAD AND SUBMITS THE <FORM>!!!!
FireFox is doing the *right* thing. I have no idea why Chrome doesn't act the same way.

**********

Two simple answers:

(1) Make sure you return false from the onclick:
Code:
<form name="this_form" method="get" action=""><!-- or omit the method -->
<input type="submit" name="submit4" value="Submit" onclick="loadNextPage(1);return false">
</form>
Simpler answer: Don't use a submit button:
Code:
<form name="this_form" method="get" action=""><!-- or omit the method -->
<input type="button" value="Submit" onclick="loadNextPage(1);">
</form>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
markman641 (11-03-2012)
Old 10-30-2012, 10:59 PM   PM User | #18
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Quote:
Originally Posted by Old Pedant View Post
You messed up.

Code:
<form name="this_form" method="POST" action="">
<input type="submit" name="submit4" value="Submit" onclick="loadNextPage(1)"></button>
</form>
First of all, that is ILLEGAL HTML. So who knows what the various browsers will do with illegal html?

You have a </button> tag but *NO* matching <button> tag.

But more than that...

Because that button is a SUBMIT BUTTON, when the loadNextPage function returns, the button GOES AHEAD AND SUBMITS THE <FORM>!!!!
FireFox is doing the *right* thing. I have no idea why Chrome doesn't act the same way.

**********

Two simple answers:

(1) Make sure you return false from the onclick:
Code:
<form name="this_form" method="get" action=""><!-- or omit the method -->
<input type="submit" name="submit4" value="Submit" onclick="loadNextPage(1);return false">
</form>
Simpler answer: Don't use a submit button:
Code:
<form name="this_form" method="get" action=""><!-- or omit the method -->
<input type="button" value="Submit" onclick="loadNextPage(1);">
</form>
It's SUPPOSED to submit the form after the last one. Also doing that completely breaks the 10 seconds disabled thing.

Last edited by markman641; 10-30-2012 at 11:07 PM..
markman641 is offline   Reply With Quote
Old 10-30-2012, 11:07 PM   PM User | #19
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
What does "after the last one" mean?

If you submit the <form>, it *WILL* rebuild the ENTIRE page, and so any change to the <iframe> *WILL* be lost. You have no choice on that.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 10-31-2012, 01:18 AM   PM User | #20
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Quote:
Originally Posted by Old Pedant View Post
What does "after the last one" mean?

If you submit the <form>, it *WILL* rebuild the ENTIRE page, and so any change to the <iframe> *WILL* be lost. You have no choice on that.
What I mean by "after the last one" is that it shows the x amount of websites in the iframe, and then when the user gets to the last one and clicks continue it ACTUALLY submits for form. It's supposed to do this so that I can move the user on to the next part of the registration process. This is exactly what chrome does.

Last edited by markman641; 10-31-2012 at 01:25 AM..
markman641 is offline   Reply With Quote
Old 10-31-2012, 04:48 PM   PM User | #21
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, you have zero code in there doing that, so far as I can see. So I haven't the foggiest idea why it works in Chrome.

You could, however, easily fix the code:
Code:
    function loadNextPage(dir) {   
        cnt += dir;
        // this can never happen: if (cnt<0) cnt=webpageArray.length-1; // wrap
        
        if (cnt>= webpageArray.length) {
            return true;
        } 
        var iframe = document.getElementById("myframe"); 
        iframe.src = webpageArray[cnt]; 
        countDown = 10;
        doCountDown( );
        $('html, body').animate({ scrollTop: 0 }, 'fast');
        return false;
    }
And then:
Code:
<input type="submit" name="submit4" value="Submit" onclick="return loadNextPage(1);">
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
markman641 (11-03-2012)
Old 11-01-2012, 01:32 AM   PM User | #22
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Quote:
Originally Posted by Old Pedant View Post
Well, you have zero code in there doing that, so far as I can see. So I haven't the foggiest idea why it works in Chrome.

You could, however, easily fix the code:
Code:
    function loadNextPage(dir) {   
        cnt += dir;
        // this can never happen: if (cnt<0) cnt=webpageArray.length-1; // wrap
        
        if (cnt>= webpageArray.length) {
            return true;
        } 
        var iframe = document.getElementById("myframe"); 
        iframe.src = webpageArray[cnt]; 
        countDown = 10;
        doCountDown( );
        $('html, body').animate({ scrollTop: 0 }, 'fast');
        return false;
    }
And then:
Code:
<input type="submit" name="submit4" value="Submit" onclick="return loadNextPage(1);">
Unfortunately firefox is still refreshing the page. Works in chrome still though.
markman641 is offline   Reply With Quote
Old 11-01-2012, 07:48 PM   PM User | #23
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
*SIGH*

You know why?

Because your code ends with:
Code:
    $('html, body').animate({ scrollTop: 0 }, 'fast');
    return false;
}
That is, you are invoking a jQuery function to do the animate, right?

BUT YOU DO NOT HAVE THE jQUERY LIBRARY LOADED on that page!!!!!!!!!

So the animate line gets an *ERROR* and the function exits on the error.
And when it exits on error there is only 1 chance in 4 billion that it will return false.

So it is returning true, because of the error, and thus allowing the submit to proceed.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
markman641 (11-03-2012)
Old 11-01-2012, 07:50 PM   PM User | #24
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
When I cloned your code and simply commented out the animate line, it worked in FF as you wanted.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
markman641 (11-03-2012)
Old 11-03-2012, 02:52 AM   PM User | #25
markman641
Regular Coder

 
Join Date: Jul 2011
Posts: 246
Thanks: 58
Thanked 1 Time in 1 Post
markman641 has a little shameless behaviour in the past
Thanks so much dude! I called the jQuery script and it worked like a charm!
markman641 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:55 PM.


Advertisement
Log in to turn off these ads.