What is an if loop????
Code:
<form>
<input name = "myname" type = "checkbox" value = "Sunday"> Sunday <br>
<input name = "myname" type = "checkbox" value = "Monday"> Monday <br>
<input name = "myname" type = "checkbox" value = "Tuesday"> Tuesday <br>
<input name = "myname" type = "checkbox" value = "Wednesday"> Wednesday <br>
<input name = "myname" type = "checkbox" value = "Thursday">Thursday <br>
<input name = "myname" type = "checkbox" value = "Friday"> Friday<br>
<input name = "myname" type = "checkbox" value = "Saturday"> Saturday<br>
<br>
<input type = "button" value = "Get Day Choices" onclick="cboxlist()"><br>
</form>
<script type = "text/javascript">
function cboxlist(){
var choice = "Your choice of day(s) is: ";
var chosen = [];
var weekdays = document.forms[0].myname;
for ( i = 0; i < weekdays.length; i++ ) {
if ( weekdays[i].checked ) {
chosen.push(weekdays[i].value);
}
}
alert (choice + (chosen.length == 0 ? 'NONE' : chosen.join(' | ')));
}
</script>
Q: How do you keep an idiot in suspense?
A: I'll tell you later
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 09-05-2012 at 10:56 AM..
|