• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic