Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2012, 10:12 PM   PM User | #1
codingcodeddode
New Coder

 
Join Date: Oct 2012
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
codingcodeddode is an unknown quantity at this point
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>
codingcodeddode is offline   Reply With Quote
Old 11-10-2012, 10:32 PM   PM User | #2
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
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>
minder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:11 AM.


Advertisement
Log in to turn off these ads.