I've about had it with this code. I am creating a form that will validate "true" fields based on if an initial checkbox was checked at the beginning. If the checkbox is unchecked, the validation does not occur.
I have created the code that can verify "true" values in each of the form elements that I am going to use. I have created a seperate code that loops to check if a certain checkbox was checked. Both work fine when I test them independently.
My problem comes when I put the "checkform" function into the "pick" function. I get errors that are stating that the objects in my "checkform" sub-functions are "null or not an object." I've defined & redefined these to death. Can someone give me some direction please!!!!
Here is the script:
<HTML>
<HEAD>
<TITLE>test</TITLE>
<SCRIPT language = "JavaScript">
function pick(frm)
{
if(frm.rad[0].checked == true)
{
alert("Checkbox " + 1 + " is checked.\n"return checkform(this.form)
}
}
function validString(str)
{
if (str.length != 0)
return true
else
return false
}
function getSelectvalue(list)
{
var listval = list.options[list.selectedIndex].value
return listval
}
function countchecks(form)
{
var numboxes = 4
var count = 0
for (i = 0; i < numboxes; i++) {
var newbox = eval("form.box" + i)
if (newbox.checked)
count++
}
return count
}
function ischecked(paytype)
{
for (i = 0; i < paytype.length; i++)
{
if (paytype.checked)
return true
}
return false
}
function checkform(form)
{
if(validString(form.fullname.value) == false)
{
alert("Please provide us with your full name"
form.fullname.focus()
return false
}
fee = getSelectvalue(form.memberlist)
if (fee == 0) {
alert("Please choose a membership category"
form.memberlist.focus()
return false
}
var numcks = countchecks(form)
if (numcks < 1) {
alert("Please choose a box"
return false
}
if (!ischecked(form.payment))
{
alert("Please choose a payment method"
return false
}
{
alert("Data is valid!"
}
}
</SCRIPT>
</HEAD>
<BODY>
<DIV CLASS="top">
<p> </p>
</DIV>
<P> Fill out the form below</P>
<FORM>
<TABLE width="400">
<TR>
<TD>Would you like to join?
<p> Yes:
<INPUT TYPE="checkbox" NAME="rad">
<INPUT TYPE="hidden" NAME="rad">
</p>
</TD>
</TR>
<TR>
<TD class="rght"><I>*Full Name</I></TD>
<TD class="lft">
<INPUT type="text" name="fullname" size="30" >
</TD>
</TR>
<TR>
<TD>select</TD>
<TD>*
<SELECT name = "memberlist">
<OPTION value = 0> Select a membership category
<OPTION value = 100> Family - $100
<OPTION value = 75> Individual - $75
<OPTION value = 50> Senior - $50
<OPTION value = 30> Youth - $30
</SELECT>
</TD>
</TR>
</TABLE>
<BR>
<TABLE WIDTH=600>
<TR>
<TD COLSPAN=2>
<B>Check all that apply.</B> </TD>
</TR>
<TR>
<TD>
<INPUT type= checkbox name = "box0">
check one<BR>
<INPUT type= checkbox name = "box1">
check two<BR>
<INPUT type= checkbox name = "box2">
check three<BR>
<INPUT type= checkbox name = "box3">
check four<BR>
</TD>
<TD BGCOLOR="silver"> <B>*Choose your method of payment.</B> <BR>
<INPUT type= radio name = "payment">
Credit card<BR>
<INPUT type= radio name = "payment" >
Bill me<BR>
</TD>
</TR>
</TABLE>
<BR>
<!--Submit button-->
<INPUT type = "button" value = "Submit Form" onClick = "return pick(this.form)">
<!--Reset button-->
<INPUT type = "reset" value = "Reset Form">
</FORM>
</BODY>
</HTML>
Thank you! Thank you! Thank you!
Randyman
I have created the code that can verify "true" values in each of the form elements that I am going to use. I have created a seperate code that loops to check if a certain checkbox was checked. Both work fine when I test them independently.
My problem comes when I put the "checkform" function into the "pick" function. I get errors that are stating that the objects in my "checkform" sub-functions are "null or not an object." I've defined & redefined these to death. Can someone give me some direction please!!!!
Here is the script:
<HTML>
<HEAD>
<TITLE>test</TITLE>
<SCRIPT language = "JavaScript">
function pick(frm)
{
if(frm.rad[0].checked == true)
{
alert("Checkbox " + 1 + " is checked.\n"return checkform(this.form)
}
}
function validString(str)
{
if (str.length != 0)
return true
else
return false
}
function getSelectvalue(list)
{
var listval = list.options[list.selectedIndex].value
return listval
}
function countchecks(form)
{
var numboxes = 4
var count = 0
for (i = 0; i < numboxes; i++) {
var newbox = eval("form.box" + i)
if (newbox.checked)
count++
}
return count
}
function ischecked(paytype)
{
for (i = 0; i < paytype.length; i++)
{
if (paytype.checked)
return true
}
return false
}
function checkform(form)
{
if(validString(form.fullname.value) == false)
{
alert("Please provide us with your full name"
form.fullname.focus()
return false
}
fee = getSelectvalue(form.memberlist)
if (fee == 0) {
alert("Please choose a membership category"
form.memberlist.focus()
return false
}
var numcks = countchecks(form)
if (numcks < 1) {
alert("Please choose a box"
return false
}
if (!ischecked(form.payment))
{
alert("Please choose a payment method"
return false
}
{
alert("Data is valid!"
}
}
</SCRIPT>
</HEAD>
<BODY>
<DIV CLASS="top">
<p> </p>
</DIV>
<P> Fill out the form below</P>
<FORM>
<TABLE width="400">
<TR>
<TD>Would you like to join?
<p> Yes:
<INPUT TYPE="checkbox" NAME="rad">
<INPUT TYPE="hidden" NAME="rad">
</p>
</TD>
</TR>
<TR>
<TD class="rght"><I>*Full Name</I></TD>
<TD class="lft">
<INPUT type="text" name="fullname" size="30" >
</TD>
</TR>
<TR>
<TD>select</TD>
<TD>*
<SELECT name = "memberlist">
<OPTION value = 0> Select a membership category
<OPTION value = 100> Family - $100
<OPTION value = 75> Individual - $75
<OPTION value = 50> Senior - $50
<OPTION value = 30> Youth - $30
</SELECT>
</TD>
</TR>
</TABLE>
<BR>
<TABLE WIDTH=600>
<TR>
<TD COLSPAN=2>
<B>Check all that apply.</B> </TD>
</TR>
<TR>
<TD>
<INPUT type= checkbox name = "box0">
check one<BR>
<INPUT type= checkbox name = "box1">
check two<BR>
<INPUT type= checkbox name = "box2">
check three<BR>
<INPUT type= checkbox name = "box3">
check four<BR>
</TD>
<TD BGCOLOR="silver"> <B>*Choose your method of payment.</B> <BR>
<INPUT type= radio name = "payment">
Credit card<BR>
<INPUT type= radio name = "payment" >
Bill me<BR>
</TD>
</TR>
</TABLE>
<BR>
<!--Submit button-->
<INPUT type = "button" value = "Submit Form" onClick = "return pick(this.form)">
<!--Reset button-->
<INPUT type = "reset" value = "Reset Form">
</FORM>
</BODY>
</HTML>
Thank you! Thank you! Thank you!
Randyman