The moose likes HTML, CSS and JavaScript and the fly likes Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Javascript" Watch "Javascript" New topic
Author

Javascript

Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
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
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
 
 
subject: Javascript
 
Threads others viewed
high cyclomatic complexity
How to avoid multiple if else
2 forms in a single page
Help with recursion
Sorting Of Array From Even Number To Odd Number
developer file tools