View Single Post
Old 09-05-2012, 10:49 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote