0

I wanted to make it change div everytime it refresh but it seems like it doesn't work. It is not random, it follow by sequence, after variable country == 1 is shown, it should country == 2.

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<meta http-equiv="refresh" content="10" >
<script type="text/javascript">


function checkRefresh()
{
    if(document.refreshForm.visited.value == "" )
    {

    var visited = document.refreshForm.visited.value = "1";
    var country = document.refreshForm.country.value = "1";

    }

    else if (country == 1 && visited == 1)
    {

    $( "boxau" ).hide( "slow" );
    $('#boxae').load('test.html').fadeIn("slow");

    country = 2;
    }

    else if (country == 2 && visited == 1)
    {

    $('#boxau').load('test.html').fadeIn("slow");
    $( "boxae" ).hide( "slow" );
    country = 1;
    }




</script>
</head>

<body onLoad="JavaScript:checkRefresh();">

<form name="refreshForm">
<input type="hidden" name="visited" value="" />
<input type="hidden" name="country" value="" />
</form>

  <div id="boxae">
    <img src='SOMEURL'>

  </div>

  <div id="boxau">
    <img src='SOMEURL'>
  </div>

</body>
</html>
Furry
  • 340
  • 1
  • 3
  • 22
  • You'll need cookies for this, or a server side session variable. Here's a SO answer on using cookies with jQuery: http://stackoverflow.com/a/1458728/2812842 – scrowler Jan 24 '14 at 03:17
  • What you're after is only really possible using server-side code or (and this comes with a few caveats) HTML5 local storage. – Nick Coad Jan 24 '14 at 03:17
  • @scrowler hmmm, that reference seems good, will give a try. – Furry Jan 24 '14 at 03:22

3 Answers3

1

This link is discussing something similar, with an example script: http://www.dynamicdrive.com/forums/s...ad.php?t=45102

Also thiis is referring to quotes there should be no unreasonable limit to the amount of text attached to each variable.

See if this points you in the right direction

Ryder
  • 53
  • 1
  • 6
-2

Edit:

Your JS variables will only be accessible cross pages if you cache them within local storage, supported by most major browsers:

http://www.w3schools.com/html/html5_webstorage.asp

If you refresh your page, you are resetting variables. The only way to counteract this is with server side code (PHP, Java, etc) and cookies.

Are you asking if it's possible to create a sequential event in which case the variable country will increment per increase?

I could make it random, but with the info in your current question I believe that wouldn't solve your problem.

Brad Larson
  • 168,330
  • 45
  • 388
  • 563
Nicholas Hazel
  • 3,710
  • 1
  • 18
  • 31
  • will increase and until the end of the last div/country, it will reset back to 1 and run over again and again – Furry Jan 24 '14 at 03:18
  • Whoah, what is with the downvotes...? – Nicholas Hazel Jan 24 '14 at 03:18
  • @NicholasHazel - did you ever think that you might be getting downvoted because your posts `are not an answer and should possibly be an edit, a comment, another question, or deleted altogether.`, and are subsequently being downvoted by SO users who view your "answer" as such? – scrowler Jan 24 '14 at 03:25
  • Considered. Not valid. Considering 2 answers got immediately downvoted the exact same number of times within 1 minute. (3) – Nicholas Hazel Jan 24 '14 at 03:27
  • @NicholasHazel suit yourself, but mine will remain in place until you propose a solution to the OP question (which is what constitutes an answer in my books) – scrowler Jan 24 '14 at 03:28
  • Deal. Let me add one sentence. – Nicholas Hazel Jan 24 '14 at 03:29
  • Done. Let me know if that doesn't answer a ridiculous Q without pretense. Writing code or copying code from the OP's perspective without understanding how to use it is disastrously dangerous. – Nicholas Hazel Jan 24 '14 at 03:32
-2

Could you add a button or another trigger for checkRefresh(), like a timeout? The page reload resets your values.

Denis C de Azevedo
  • 5,971
  • 2
  • 28
  • 46
  • I can't add a button into it, this code will be placed into a raspberry pi as web kiosk – Furry Jan 24 '14 at 03:20