...

View Full Version : Switch



codingcodeddode
11-10-2012, 10:12 PM
This is what my code needs to do
When i click sunday i get an alert message saying 'works' using the switch statements




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

minder
11-10-2012, 10:32 PM
<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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum