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 2 of 2

Thread: Switch

  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Switch

    This is what my code needs to do
    When i click sunday i get an alert message saying 'works' using the switch statements


    Code:
    <html>
    <head>
     <title>
     
     </title>
     
     <script type='text/javascript'>
    
    
     
     var runme = function(){
     
     var week = document.getElementById('textBox').value;
    	switch(week){
    		case document.getElementById('sunday').checked:
    			alert('works');
    	}
    }
    	
     </script>
     
     </head>
     
     <body>
     
    	<input type='radio' name='week' value='sunday' id='sunday' onclick='runme();'>Sunday<br>
    	<input type='radio' name='week' value='monday' id='monday' onclick='runme();'>Monday<br>
    	<input type='radio' name='week' value='tuesday' id='tuesday' onclick='runme();'>Tuesday<br>
    	<input type='radio' name='week' value='wednssday' id='wednesday' onclick='runme();'>Wednesday<br>
    	<input type='radio' name='week' value='thursday' id='thursday' onclick='runme();'>Thursday<br>
    	<input type='radio' name='week' value='friday' id='friday' onclick='runme();'>Friday<br>
    	<input type='radio' name='week' value='saturday' id='saturday' onclick='runme();'>Saturday<br>
    	<input value='Your Choice: ' id='textBox'>
    
     </body>
    
    </html>

  • #2
    Banned
    Join Date
    Oct 2012
    Posts
    81
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Code:
        <body>
            <input type='radio' name='txtWeek' value='sunday' id='sunday' onclick='runme(this.value);' />Sunday<br /> 
            <input type='radio' name='txtWeek' value='monday' id='monday' onclick='runme(this.value);' />Monday<br /> 
            <input type='radio' name='txtWeek' value='tuesday' id='tuesday' onclick='runme(this.value);' />Tuesday<br /> 
            <input type='radio' name='txtWeek' value='wednssday' id='wednesday' onclick='runme(this.value);' />Wednesday<br /> 
            <input type='radio' name='txtWeek' value='thursday' id='thursday' onclick='runme(this.value);' />Thursday<br /> 
            <input type='radio' name='txtWeek' value='friday' id='friday' onclick='runme(this.value);' />Friday<br /> 
            <input type='radio' name='txtWeek' value='saturday' id='saturday' onclick='runme(this.value);' />Saturday<br /> 
            <input value='Your Choice: ' id='txtResult' />
            <script type='text/javascript'> 
                function runme(val) { 
                    switch(val){ 
                        case  'sunday': 
                            alert('works'); 
                    } 
                } 
            </script>
        </body>


  •  

    Posting Permissions

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