codetoad.com
Home||ASP|ASP.Net|C++/C#|DHTML|HTML|Java|Javascript|Perl|VB|XML||CodeToadPlus!||Forums||RAM
Search Site:
Search Forums:
Unique Checkbox problem. Archive Import (Al Justice) at 13:43 on Monday, July 14, 2003

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.

Re: Unique Checkbox problem. Troy Wolf at 11:05 on Tuesday, July 15, 2003

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)
Troy Wolf: site expert
SnippetEdit Website Editor


Re: Unique Checkbox problem. Archive Import (Al Justice) at 11:20 on Tuesday, July 15, 2003

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>



Re: Unique Checkbox problem. Troy Wolf at 11:34 on Tuesday, July 15, 2003

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!
Troy Wolf: site expert
SnippetEdit Website Editor


Re: Unique Checkbox problem. Archive Import (Al Justice) at 11:47 on Tuesday, July 15, 2003

Makes very good sense--I`ll give`r a try. I`ll let you know... thanks Troy.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
matrix addition
Re: Storing data from HTML to Excel or TXT
Re: function within loop problem
Re: Ô‡´ò¥¯¥é¥Ö¤Ï ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
Re: Replace
Re: タイトリスト AP2アイアン 712�情�
Re: SMS from Perl using HTTP request
Re: Charl Schwartzel
Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


Copyright codetoad.com 2001-2013