Replies To: Help needed with Check box form validation

Re: Help needed with Check box form validation

Posted 30 October 2008 - 10:57 AM

There are a couple problems but to get you started in the right direction consider the following. You checkbox names are "Location[x]" which means you will need to directly call each checkbox by its name like getElementById('Location[x]'). What I think you are trying to accomplish is to name all the checkboxes the same <....name="Location"....> Then in your code you can access them like this

Re: Help needed with Check box form validation

Posted 30 October 2008 - 11:24 AM

xerxes333, on 30 Oct, 2008 - 10:57 AM, said:

There are a couple problems but to get you started in the right direction consider the following. You checkbox names are "Location[x]" which means you will need to directly call each checkbox by its name like getElementById('Location[x]'). What I think you are trying to accomplish is to name all the checkboxes the same <....name="Location"....> Then in your code you can access them like this

Re: Help needed with Check box form validation

Posted 30 October 2008 - 11:44 AM

No the id attribute needs to be unique. If you cannot control the name of the input element ten I would suggest something like this.

var inputs = workorderNew.getElementsByTagName('input');
//loop through all the input elements in the form
for(i=0;i<inputs.length;i++){
//if the current element is a checkbox grab it
if(inputs[i].getAttribute('type') == 'checkbox'){
var chk = inputs[i];
//do stuff with the checkbox
//blah
//blah
//blah
}
}

Re: Help needed with Check box form validation

Posted 30 October 2008 - 12:22 PM

Well I am trying a new way and stuck again, I'm really learning today to dislike javascript
Anyways can someone Please help me figure this out, I thought maybe it would be easier to use the getElementById. but I'm all messed up with the phrasing at this point

Re: Help needed with Check box form validation

If that still doesn't work, I would remove the "with" statement and call the object directly. I have found out in the past that what I think I'm working "with" is not the same as what the computer thinks it is operating "with". To assure youself of the proper check, I would scatter a few alerts("message") about to see what the values are where you expect them to be.

Re: Help needed with Check box form validation

Posted 30 October 2008 - 01:34 PM

try posting all the code (clean it up first) because I'm sure you function is working fine but I suspect the method that you are using to submit the form is whats screwing things up. Also if you notice the code I posted previously, it works just fine. Cut/paste it into a new file and try it yourself if you don't believe me.

Re: Help needed with Check box form validation

Posted 30 October 2008 - 01:58 PM

Moving right along found something that looks like it should work, but it doesn't
I agree the form field 'location' all being the same name for the checkboxes is the problem
right...
But look at this it should work some how but I think I have to use getElementById because I can give the checkboxes their own id's