html/javascript link code not working no matter how I put it.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tpgames
    Contributor
    • Jan 2007
    • 783

    html/javascript link code not working no matter how I put it.

    Code:
    <a href="javascript:selectLetter('A')" + document.body.aLink;" >A</a> | 
    <a href="javascript:selectLetter('B')" + document.body.aLink;>B</a>
    I've read the JS Bible, JS for the WWW, and Visual JS and have not found the answer to what I'm trying to do. I need the link to access the CSS sheet so that after the link is pressed, it will turn red from blue. The usual
    Code:
    <body onLoad="function1();">
    <script>
    	function function1() {
    		document.body.aLink = "red";
    	}
    </script>
    <a href="http://www.link.com/"> link.vom (click to turn red)</a>
    </body>[color=#000000]
    [/color][color=#000000][/color]
    that I found, doesn't really do what I want it to do.

    Thanks!
  • tpgames
    Contributor
    • Jan 2007
    • 783

    #2
    I tried using a DIV tag, but that didn't change a think with the links.
    Code:
    CSS Sheet has :
    div.navLink a:link { color:#0000ff; text-decoration: underline; }
    div.navLink a:visited { color:#ff0000; text-decoration: underline; }
    div.navLink a:hover { color:#0000ff; font-weight: font-size: 24px;}
    div.navLink a:active { color:#0000ff; text-decoration: underline; }
    
    The HTML page has:
    <div class="navLink">
    That didn't worked.

    Link to Full Code.

    Comment

    • tpgames
      Contributor
      • Jan 2007
      • 783

      #3
      Now that I think about it, I really need the link to reset itself to Blue when the "start game/ reset game" button is pushed.

      So, what I really need to accomplish is:
      click on blue link, link changes to red.
      click on "reset game", link changes back to blue.

      I've successfully made regular html links before that changed colours. It amazing that nothing is working here, only because of a silly JS type link.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Use an onclick to change the colour, e.g.
        [code=javascript]onclick="this.s tyle.color='#ff 0000'"[/code] link

        Comment

        • tpgames
          Contributor
          • Jan 2007
          • 783

          #5
          I knew their was something really obvious I forgot to try. Thanks!

          Comment

          • tpgames
            Contributor
            • Jan 2007
            • 783

            #6
            Okay, if I do offclick to change the color back, it will change it back before It want it too. The reset button doesn't change the links back to blue. What code would cause the reset button to change all the links back to blue?

            Is there a onreset code? something like
            Code:
            onreset="this.style.color='#0000ff'"?
            I know that the above doesn't work, but something like it.
            Thanks!

            Comment

            • pronerd
              Recognized Expert Contributor
              • Nov 2006
              • 392

              #7
              Originally posted by tpgames
              The reset button doesn't change the links back to blue. What code would cause the reset button to change all the links back to blue?
              Code:
                      <button id="someIdName" onClick="this.style.color='#0000ff';" />

              Comment

              • tpgames
                Contributor
                • Jan 2007
                • 783

                #8
                I'd delete this message if it were allowed.
                Last edited by tpgames; Apr 30 '08, 02:27 PM. Reason: useless with above info.

                Comment

                • tpgames
                  Contributor
                  • Jan 2007
                  • 783

                  #9
                  Originally posted by pronerd
                  Code:
                          <button id="someIdName" onClick="this.style.color='#0000ff';" />
                  This is what I have to cause the click of the letter to change the link to red.
                  Code:
                  <a href="javascript:selectLetter('A');" onclick="this.style.color='#ff0000'">A</a> | 
                  <a href="javascript:selectLetter('B');" onclick="this.style.color='#ff0000'">B</a> | 
                  <a href="javascript:selectLetter('C');" onclick="this.style.color='#ff0000'">C</a> |
                  Where would I put your code to revert all the links back to blue after the person has reset the page?

                  Comment

                  • pronerd
                    Recognized Expert Contributor
                    • Nov 2006
                    • 392

                    #10
                    Originally posted by tpgames
                    The reset button doesn't change the links back to blue. What code would cause the reset button to change all the links back to blue?
                    Where is the HTML for this "reset button" you mentioned before?



                    Originally posted by tpgames
                    Where would I put your code to revert all the links back to blue after the person has reset the page?
                    Since the question relates to resetting the page it would be more productive to display the code that does this reset

                    Comment

                    • tpgames
                      Contributor
                      • Jan 2007
                      • 783

                      #11
                      Here's the requested code. I took a nap so that I could look at this anew.

                      Code:
                      function reset()
                      {
                      selectWord();
                      document.game.usedLetters.value = "";
                      used_letters = "";
                      wrong_guesses = 0;
                      document.hm.src="hmstart.gif";
                      }
                      Code:
                      <body onLoad="reset(); return true;">
                      
                      <snip>
                      <a href="javascript:selectLetter('C');" onclick="this.style.color='#ff0000'">C</a> | 
                      <a href="javascript:selectLetter('D');" onclick="this.style.color='#ff0000'">D</a> | 
                      <snip>
                      
                      <a href="javascript:reset()">Start game / Reset game</a>
                      I tried adding a function thing that would reset the links to blue, but that didn't work. I'm still trying to understand JS coding language.
                      Thanks! :D

                      Comment

                      • tpgames
                        Contributor
                        • Jan 2007
                        • 783

                        #12
                        Here is again, the link to the full code. Just view the source code.

                        Its my version of a hangman game. I'm calling it Evaporating Book.

                        Comment

                        • tpgames
                          Contributor
                          • Jan 2007
                          • 783

                          #13
                          Just to be sure it is understood what I am trying to do:

                          User: clicks on letter link to guess word.
                          Code:
                          <a href="javascript:selectLetter('X');">X</a> | 
                          <a href="javascript:selectLetter('Y');">Y</a> | 
                          <a href="javascript:selectLetter('Z');">Z</a> </center> </p>
                          Link changes from blue to red.

                          User continues clicking on letter links until word guessed.
                          Links continue to change from blue to red as they are clicked.
                          User guesses word correctly then click Reset button.
                          Page resets all forms, so that they can play a brand new game.
                          Except with the current code, the now red links, stay red. Only a reload of the page will change them to blue.

                          I want these red links to revert back to the original blue so that the user can reclick them to change them to red as they guess new letters when they start a new game.

                          Comment

                          • tpgames
                            Contributor
                            • Jan 2007
                            • 783

                            #14
                            I find it I totally ignore the reset function and instead put in a reload page, everything resets itself. However, I'm still curious as to how else one would do this.

                            Here's the code I found that does the trick, but makes my JS reset function useless:
                            Code:
                            <input type="button" value="Start game / Reset game" onClick="window.location.reload()">
                            I've not tested it in IE yet, only FF.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              Rather than reloading the page, get all the links on the page, loop over them and set the colour to blue:
                              [code=javascript]var links = document.getEle mentsByTagName( "a");
                              for (i = 0; i < links.length; i++) {
                              links[i].style.color = "#0000ff";
                              }[/code]

                              Comment

                              Working...