IntelliJ Java IDE
The moose likes HTML, CSS and JavaScript and the fly likes Problem placing variable value in for loop 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 "Problem placing variable value in for loop" Watch "Problem placing variable value in for loop" New topic
Author

Problem placing variable value in for loop

age spets
Ranch Hand

Joined: Aug 07, 2002
Posts: 68
function bestille()
{
var antBestillinger = document.husleieBestille.antBestillinger.value;
var ant = 0;
for (ant;ant<antBestillinger;ant++)
{
ant=ant+1;
****not working***if(document.husleieBestille.cBox[ant].checked)
{
showTestB();
}
else
{
showikkeHuketavB();
}
}
}
Trying to figure out a good way to write this code to see if checkboxes are checked or not. If I replace [ant] with f.instance 1 or 2(the number the checkbox I get correct value. How do I place the ant value in the code correctly?
Yours Age
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
try doing this
function bestille(){
var antBestillinger = document.husleieBestille.antBestillinger.value*1;
for (ant=0;ant<antBestillinger;ant++){
if(document.husleieBestille["cBox"+ant].checked){
showTestB();
}
else{
showikkeHuketavB();
}
}
}

Now do you have a CBox named CBox0??
eric
age spets
Ranch Hand

Joined: Aug 07, 2002
Posts: 68
Thank you soo much:-) Perfect. Had problems to understand why you did not have to put the dot after husleieBestille..
like:
if(document.husleieBestille.["cBox"+ant].checked)
instead of:
if(document.husleieBestille["cBox"+ant].checked)
All the solutions I tried I did that and that created the mess. Javascript is not very easy for debugging. Do Anyone know some good pages for javascript or good software for javascript debugging to download?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
I personally just figure out erors from the little IE warning. Coding in this for years, so i have gotten used to it.
The mozilla browser has a javascript debuging console in it. Put rate it very high.
Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
OH, forgot to say the reason for the missing dot is this.
The elements on the page act like a large array. They are all stored in it
TheForm = document.form[0].elements;
Each form element can be acessed in the array
TheForm[0].value="THe firt Element";
Bad explaination, but worth a shot!
Eric
 
 
subject: Problem placing variable value in for loop
 
Threads others viewed
finding the value of a radio button
[JSTL] how can I convert values (string to int) in JSTL
check boxes retrieving problem
problem while using input type="checkbox"
Read the respective row when a check box checked
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com