for(var k=0; k<document.form1.places.length; k++) { if(document.form1.places[k].checked) str += document.form1.places[k].value + "\n"; } The above works correctly giving me the list of places I have visited. if(document.form1.places.length == 0) { message += "You did not visit any places in the last one year. \n"; } else if (document.form1.places.length == 1) { message += "You visited one place: \n" + str; } else message += "You visited more than one place: \n" + str ; Why does my dialog box always go to the message showing more than one place? It prints the correct string but the initial message is always the third option. How do I correct it?
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
posted
0
because you are not lookig at the number checked, only the number of checkboxes... in your loop you need to keep track of how many were selected! In the fuure please use code tags around you code! Eric