|
I have a form that returns another form with a table of records and checkboxes on the second form. Under some circumstances the second form will only return one record.
My checkbox validator does not recognize a single checkbox if there are not more than one records on the second form. I`ve tried changing the length condition, and several other things with no luck. Any suggestions?
Classic ASP--not dot-net.
|
|
|
I`m familiar with a few methods of working with checkboxes in both javascript client-side and VBScript server-side. How are you doing your validation? On the client before form submission or on the server after form submission? Can you post the code that you have to validate the checkboxes? (Or you can email me direct if you prefer. troy[at]troywolf.com)
|
|
|
|
|
The second `returned` form is pretty complex, but my current validation is as follows:
If only one record is returned based on my query, the script loses it`s functionality, sees 0 records as having been chosen, and will not process the record according the the box I`ve selected.
<script type="text/javascript">
<!--
function checkEntries(CreateWeeklyView)
{
// set vars for various checkbox_choices to zero
var checkbox_choices = 0;
var checkbox_choices1 = 0;
var checkbox_choices2 = 0;
// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < CreateWeeklyView.toSelect.length; counter++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if ( CreateWeeklyView.toSelect[counter].checked)
{ checkbox_choices = checkbox_choices + 1;
document.CreateWeeklyView.optionChosen.value = `w`;
}
}
// Loop from zero to the one minus the number of checkbox button selections
for (counter1 = 0; counter1 < CreateWeeklyView.toSelect1.length; counter1++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if ( CreateWeeklyView.toSelect1[counter1].checked)
{ checkbox_choices1 = checkbox_choices1 + 1;
document.CreateWeeklyView.optionChosen.value = `q`;
}
}
// Loop from zero to the one minus the number of checkbox button selections
for (counter2 = 0; counter2 < CreateWeeklyView.toSelect2.length; counter2++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if ( CreateWeeklyView.toSelect2[counter2].checked)
{ checkbox_choices2 = checkbox_choices2 + 1;
document.CreateWeeklyView.optionChosen.value = `p`;
}
}
if ((checkbox_choices < 1) && (checkbox_choices1 < 1) && (checkbox_choices2 < 1))
{
// If there were less then selections made display an alert box
alert("Please make at least 1 selection. \n" + checkbox_choices + " entered so far.")
return (false);
}
// If three were selected then continue processing
return (true);
}
-->
</script>
|
|
|
OK...now, I haven`t run any test code, but I think I ran into this same thing before and I found the problem was with this line:
for (counter = 0; counter < CreateWeeklyView.toSelect.length; counter++)
The problem is that when only one checkbox is checked, the element is not an array, so ".length" does not exist. I think I had to do something like this:
if(CreateWeeklyView.toSelect.length) {
//do array processing here like you already are
} else {
//directly process the element
if(CreateWeeklyView.toSelect.checked) {
//do your processing here
}
}
Get it? First see if the element is an array, if so, process the array like you are, otherwise, process the individual element.
Hope this helps. If I`m way off --sorry!
|
|
|
|
|
Makes very good sense--I`ll give`r a try. I`ll let you know... thanks Troy.
|
|
|
|
|
|
|
|