www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: How to fix Ďalertí that affects inner.html display?

  1. #1
    Join Date
    Apr 2009
    Posts
    49

    Question How to fix Ďalertí that affects inner.html display?

    A game Iím working on has several rounds of play. After each round an alert shows ĎCorrectí or ĎIncorrect.í Then a cumulative score is displayed in a separate div using inner.html. All of that works well. So I took out the alert. Now, when the round is over the screen flashes to the next round without displaying the cumulative score. Possibly the cumulative score is displayed momentarily, but that does no good. How do I fix this?
    Thanks.

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    we need some code

  3. #3
    Join Date
    Apr 2009
    Posts
    49
    Relevant code is shown below (out of ~300 lines). The function is in the head; the div is in the body. If you need the whole thing let me know.

    function showScore()
    {if (success==1 && games<playGames) {msg0=msg1; }
    else if (success==-1 && games<playGames) {msg0=msg2; }
    //alert(msg0);
    var gg="Rounds";
    if (games==1) {gg="Round"}
    var ww="Wins";
    if (wins==1) {ww="Win"}
    score = "<center><table border=3 bgcolor=#B4FBAA cellpadding=1 cellspacing=1 height=34 width=536><tbody valign=middle align=center><tr><td><font face='Verdana' size='2'>"+games+" "+gg+" played, "+wins+" "+ww+". You've earned "+poynts+" out of a possible "+mxpoynts+" points.</font></td></tr></tbody></table></center>";
    document.getElementById('mynum').innerHTML = score;
    }

    <div id="myoutput" style="margin:20px 0 0 0">
    <div id="mynum" style="display:inline">
    </div>
    </div>

  4. #4
    Join Date
    Oct 2006
    Posts
    939
    try using the triple evaluator throughout the code
    if(games==1) might evaluate to true
    if(games===1) would evaluate to the number

  5. #5
    Join Date
    Apr 2009
    Posts
    49
    I tried the suggestion both in the function only, and then throughout the code. Neither worked...display still flashes to the next round of the game without showing the current score. When I reactivated the alert, then the current score was shown. I watched carefully...the 'flash' seems to go from the correct display to an instantaneous white screen and then to the correct display again. Maybe that's a clue? Any other thoughts?

  6. #6
    Join Date
    Oct 2006
    Posts
    939
    split your function in two after the alert.
    insert a setTimeout("func2()",100) delay to finish the function.

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364
    Are you using a <form> tag?

  8. #8
    Join Date
    Apr 2009
    Posts
    49
    Below is the code after trying several different ways to do as you suggested. My guess is that I don't understand how to incorporate it. Could you mark up the code the right way?
    Re. using <form>...there is one use of it in the game portion itself, but not in the div where the score summary is placed.
    I'm in over my head...hope you guys can help me out!
    -------------------------------
    function showScore()
    {if (success==1 && games<playGames) {msg0=msg1; }
    else if (success==-1 && games<playGames) {msg0=msg2; }
    // setTimeout("func2()",1000);
    //alert(msg0);
    func2();
    }

    function func2()
    {setTimeout("func2()",1000);
    var gg="Rounds";
    if (games==1) {gg="Round"}
    var ww="Wins";
    if (wins==1) {ww="Win"}
    score = "<center><table border=3 bgcolor=#B4FBAA cellpadding=1 cellspacing=1 height=34 width=536><tbody valign=middle align=center><tr><td><font face='Verdana' size='2'>"+games+" "+gg+" played, "+wins+" "+ww+". You've earned "+poynts+" out of a possible "+mxpoynts+" points.</font></td></tr></tbody></table></center>";
    document.getElementById('mynum').innerHTML = score;
    }

  9. #9
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364
    Post a link to the game so we can see the interactions of the HTML and JS etc.

  10. #10
    Join Date
    Apr 2009
    Posts
    49
    The game's not yet on internet, so no link. With your permission may I email a zip file to you with the code, js file and other necessary files? Don't want to do that unless you say okay (either of you). Please let me know...and thanks in advance for your great help.

  11. #11
    Join Date
    Oct 2006
    Posts
    939
    you can upload it like this...
    Attached Files Attached Files

  12. #12
    Join Date
    Apr 2009
    Posts
    49
    Here are the files. the alert we've been dealing with is in line 78 of the main code. Thanks.
    Attached Files Attached Files

  13. #13
    Join Date
    Oct 2006
    Posts
    939
    Ok great. Now give us the answers so we can let the code run through and see whats happening.

  14. #14
    Join Date
    Oct 2006
    Posts
    939
    I found var rand and set it to 1
    I spell the word but you don't show score,
    Can you write some convenience to show what is to happen for dummies?

  15. #15
    Join Date
    Apr 2009
    Posts
    49
    The js file contains a 'gw' array with the Greek words, and a 'def' array with the definitions (hints). The code randomly presents a Greek word to be discovered so I can't pinpoint which one to define. You could reduce the length of each array in the js file to, say, 3, so it has a limited number of words to work with. If you do that, also set 'playGames' to 3 (it's on line 48).

    The code (and the problem I'm having) works whether or not you get the word right. Just click on any of the letters until you run out of guesses, and it will still display the current score. But it only does that when the alert is used. With the alert turned off by '//' the current score does not display.

    Thanks...your quick responses are GREATLY appreciated.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles