Z
zephyr
Hi,
I have a hidden field in my form:
<input type="hidden" name="checkBoxesCollection" value="">
If I submit the form I call a javascript function:
function storeCheckboxFieldNames(theForm){
var inputElements = theForm.getElementsByTagName("input");
var collection = document.getElementsByName("checkBoxesCollection");
alert(collection[0].value);
for(i=0; i<inputElements.length; i++){
// if(inputElements.type == "checkbox")
// collection.value = collection.value + inputElements.name +
",";
}
// collection.value =
collection.value.substr(0,collection.value.length);
// alert(collection.value);
}
(I commented lines to see the effect of only the first 3 lines).
Running this function gives me an alert with the names of _all_
fieldnames in the form. I thought this should just output the value of
the first element by the name of "checkBoxesCollection" - which is ""
Can anyone explain this??
btw
If I use document.getElenmentById instead document.getElementsByName
the function works exactly as designed: concat all names of checkboxes
in the form and assign them to the value of the hidden field.
function storeCheckboxFieldNames(theForm){
var inputElements = document.getElementsByTagName("input");
var collection = document.getElementById("checkBoxesCollection");
for(i=0; i<inputElements.length; i++){
if(inputElements.type == "checkbox")
collection.value = collection.value + inputElements.name + ",";
}
collection.value =
collection.value.substr(0,collection.value.length-1);
alert(collection.value);
}
I have a hidden field in my form:
<input type="hidden" name="checkBoxesCollection" value="">
If I submit the form I call a javascript function:
function storeCheckboxFieldNames(theForm){
var inputElements = theForm.getElementsByTagName("input");
var collection = document.getElementsByName("checkBoxesCollection");
alert(collection[0].value);
for(i=0; i<inputElements.length; i++){
// if(inputElements.type == "checkbox")
// collection.value = collection.value + inputElements.name +
",";
}
// collection.value =
collection.value.substr(0,collection.value.length);
// alert(collection.value);
}
(I commented lines to see the effect of only the first 3 lines).
Running this function gives me an alert with the names of _all_
fieldnames in the form. I thought this should just output the value of
the first element by the name of "checkBoxesCollection" - which is ""
Can anyone explain this??
btw
If I use document.getElenmentById instead document.getElementsByName
the function works exactly as designed: concat all names of checkboxes
in the form and assign them to the value of the hidden field.
function storeCheckboxFieldNames(theForm){
var inputElements = document.getElementsByTagName("input");
var collection = document.getElementById("checkBoxesCollection");
for(i=0; i<inputElements.length; i++){
if(inputElements.type == "checkbox")
collection.value = collection.value + inputElements.name + ",";
}
collection.value =
collection.value.substr(0,collection.value.length-1);
alert(collection.value);
}