CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Sep 2008
    Posts
    3

    javascript switch case statement.

    I'm new to the switch statement and I'm trying to put the case one value in "onmouseover="getValue(1)"" and can't seem to get it to work. Could someone tell me what I'm doing wrong

    Also I'll have several cases because this is going to be a yahtzee game.

    Code:
    function getValue(category)
      {
        d = new Array(6);
        
        for(var i = 0; i < 5; i++)
        {
    // parses values from numbered pictures and plases them into another      // array for sorting
          d[i] = 1 * dice[i].src.charAt(dice[i].src.length - 5);
        }
        d.sort();
        
        switch(category)
        {
          case 1:
          {
               // Counts the ones in d[]
                for(var i = 1; i < 6; i++)
    	  	{
    	  	  if(d[i] == 1)
    	  	  {
    	  	    ones++;
    	  	  }
    	  	}
    	  	return ones;
          }
          break;
        }
                    
      }
    
    //html
    
    <tr>
          <td><label id="Label1">Ones</label></td>
          <td><input id="category" name="Category1" type="text"   nmouseover = "getValue(1)" /></td>
    </tr>
    Last edited by PeejAvery; September 20th, 2008 at 12:05 PM. Reason: Added code tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured