Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to link arrow key to code

    This is my code, i need to link arrow keys to be able to select a "Smash" or "Dash" . this is my code
    Code:
    <!doctype html>
    <head>
    <style>
        body {
            background-color: hotPink;        
            background-image: "bground.jpg";
            text-align: center;
        }            
        
        section {
            width: 40%;
            display: inline-block;
        }    
        
        button {
            color: #444;
            background-color: #B5B198; 
            border: 1px solid #999;    
            border-radius: 6px; 
            background-clip: padding-box;
            font-weight: bold;
            font-size: 5em;
            margin: 20px;
            text-shadow: -1px -1px #ccc;
            cursor: pointer;
        }
        
        img {
            border: 0;
        }  
        
        .score {
          color: white;
          font-size: 2em;
          font-family: sans-serif;
        }        
    
        .copyright-amirite {
               color: #FF3399;
        }
                        
    </style>
    </head>
    <body onload="displayGirl();" >
    
       
        <div>
          <img id="image" height=500 width=350>
        </div>
        
        <section id="smash">
            <p class="score">0</p>
            <button>SMASH!</button>
        </section>
        <section id="dash">
            <p class="score">0</p>
            <button>Dash!</button>
        </section>
        
        <script>
            var count;
            var choice;
            var images = [];
            var image = document.getElementById( "image" );
            var smash = document.getElementById( "smash" );
            var dash = document.getElementById( "dash" );
            
            for ( count = 0; count < 310; count++ ) {
                var string = "/graphic (COUNT).jpg";
                images[ count ] = string.replace( "COUNT", count );
            }
            
            function chooseRandom( range ) {
                return Math.floor( Math.random() * ( images.length - 1 ) );
            }
            
            function displayGirl() {
                choice = chooseRandom( images.length );
                image.src = images[ choice ];
            }
            
            function update() {
                var button = this;
                var score = button.previousElementSibling;  
                score.innerHTML = +score.innerHTML + 1;
                displayGirl();
            }
            
            [ smash, dash ].forEach(function( section ) {
              var button = section.children[1];
              button.addEventListener( "click", update, false );
            });
            
        </script>
    Last edited by VIPStephan; 10-30-2012 at 01:51 PM. Reason: added code BB tags

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Please enclose your code between code tags. Easier to read.

    This is not the forum to ask questions. This is for posting scripts that already work and others might find useful. I'm sure a moderator will move this post, at some point. Just a heads-up.

    I see you using jQuery code, but I don't see you loading jQuery.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,642
    Thanks
    6
    Thanked 1,005 Times in 978 Posts
    Moved to appropriate forum.

    WolfShade, where do you see the OP use jQuery?

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I could be wrong. The following _looked_ like jQuery code, to me:
    Code:
    [ smash, dash ].forEach(function( section ) {
               var button = section.children[1];
               button.addEventListener( "click", update, false );
             });
    But I'm not fully awake. A closer look, and I realize, now. Caffeine.. IV drip.. stat!
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Tags for this Thread

    Posting Permissions

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