Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem validating a form

    How can I combine these 2 functions?

    function POvalidator()
    {
    var obj = document.Form1;
    if (obj.PONumber.value == "") {
    alert("Please enter a value for the PO Number field.");
    obj.PONumber.focus();
    return false;
    }

    }


    function checkCheckBox(){
    if (f.agree.checked == false )
    {
    alert("Tou must agree to the Terms to continue");
    return false;
    }else
    return true;
    }

    They work separately, but I can't get them to work together.

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by KeithWarren View Post
    How can I combine these 2 functions?
    They work separately, but I can't get them to work together.
    Assuming thatyou mean that you want to call them both sequentially, presumably when the form is submitted:

    <FORM ....... onsubmit="return POvalidator() && checkCheckBox()">

    I suggest that you fix POvalidator so that it returns true explicitly.

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that.

    It only works on the text field, not on the Check Box.

    For example, I want force the user to check the box and put an entry in the text field. Currently, as long as the text field has an entry, the form submits. It's not verifying the checkbox.

    Any other ideas.

  • #4
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by KeithWarren View Post
    I tried that.

    It only works on the text field, not on the Check Box.

    For example, I want force the user to check the box and put an entry in the text field. Currently, as long as the text field has an entry, the form submits. It's not verifying the checkbox.

    Any other ideas.
    That suggests a problem with checkCheckBox. If there are no console errors, you'll have to show your entire code.

  • #5
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the latest script code.

    <SCRIPT language="JavaScript" type="text/javascript">

    function POvalidator()
    {
    var obj = document.Form1;
    if (obj.PONumber.value == "") {
    alert("Please enter a value for the PO Number field.");
    obj.PONumber.focus();
    return false;
    }
    return true;
    }


    function checkCheckBox(){
    if (form1.agree.checked == false )
    {
    alert("Tou must agree to the Terms to continue");
    return false;
    }else
    return true;
    }

    </SCRIPT>


    And here's the code for the form.

    <form name="Form1" id="Form1" method="post" action="order_confirmation.asp" onsubmit="return POvalidator() && checkCheckBox()">
    <table width="590" border="1" cellpadding="5" cellspacing="0" bordercolor="#f2f2f2">
    <tr>
    <td width="150" bgcolor="#f2f2f2"><div align="center" class="blueheading">PRINT QUOTE </div></td>
    <td width="440" bgcolor="#f2f2f2"><div align="center" class="blueheading">PLACE ORDER </div></td>
    </tr>
    <tr>
    <td><div align="center"><a href="quote.asp"><img src="printquote-button.jpg" width="68" height="22" border="0" /></a></div></td>
    <td><div align="center">
    <table width="420" border="0" cellspacing="0" cellpadding="0" class="bodytext">
    <tr>
    <td height="25" colspan="3">
    <div align="center">
    <table width="400" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="350"><div align="center">To place an order, you must agree to the <a href="Terms.htm">Terms
    &amp; Conditions</a>. I agree:

    </div>
    <div align="left" class="bodytext"></div> <div align="center">

    </div></td>
    <td width="50"><div align="left" class="bodytext"><input type="checkbox" value="0" name="agree"></div></td>
    </tr>
    </table>
    </div></td>
    </tr>
    <tr>
    <td width="120" height="25"><div align="right" class="bodytext">PO Number </div></td>
    <td width="200"><div align="left">
    <input type="text" name="PONumber" size=12 style="font-family: Tahoma; font-size: 8pt">
    <%session("PONumber") = Request.Form("PONumber")%></div> </td>
    <td width="100">&nbsp;</td>
    </tr>
    <tr>
    <td height="25"><div align="right" class="bodytext">Attention To </div></td>
    <td><div align="left">
    <input name=Attention size=20 style="font-family: Tahoma; font-size: 8pt">
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td height="25"><div align="right" class="bodytext">Comment</div></td>
    <td><div align="left">
    <input name=Comment size=35 style="font-family: Tahoma; font-size: 8pt">
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><div align="right"></div></td>
    <td><input type="hidden" name="ShippingMethod" value="<%=Session("ShippingMethod")%>">

    <input type="hidden" name="Size10" value="<%=Session("SphereSize10")%>">
    <input type="hidden" name="Size9" value="<%=Session("SphereSize9")%>">
    <input type="hidden" name="Size8" value="<%=Session("SphereSize8")%>">
    <input type="hidden" name="Size7" value="<%=Session("SphereSize7")%>">
    <input type="hidden" name="Size6" value="<%=Session("SphereSize6")%>">
    <input type="hidden" name="Size5" value="<%=Session("SphereSize5")%>">
    <input type="hidden" name="Size4" value="<%=Session("SphereSize4")%>">
    <input type="hidden" name="Size3" value="<%=Session("SphereSize3")%>">
    <input type="hidden" name="Size2" value="<%=Session("SphereSize2")%>">
    <input type="hidden" name="Size1" value="<%=Session("SphereSize1")%>">
    <input type="hidden" name="Qty10" value="<%=Session("SphereQty10")%>">
    <input type="hidden" name="Qty9" value="<%=Session("SphereQty9")%>">
    <input type="hidden" name="Qty8" value="<%=Session("SphereQty8")%>">
    <input type="hidden" name="Qty7" value="<%=Session("SphereQty7")%>">
    <input type="hidden" name="Qty6" value="<%=Session("SphereQty6")%>">
    <input type="hidden" name="Qty5" value="<%=Session("SphereQty5")%>">
    <input type="hidden" name="Qty4" value="<%=Session("SphereQty4")%>">
    <input type="hidden" name="Qty3" value="<%=Session("SphereQty3")%>">
    <input type="hidden" name="Qty2" value="<%=Session("SphereQty2")%>">
    <input type="hidden" name="Qty1" value="<%=Session("SphereQty1")%>">
    <input type="hidden" name="Alloy10" value="<%=Session("SphereAlloy10")%>">
    <input type="hidden" name="Alloy9" value="<%=Session("SphereAlloy9")%>">
    <input type="hidden" name="Alloy8" value="<%=Session("SphereAlloy8")%>">
    <input type="hidden" name="Alloy7" value="<%=Session("SphereAlloy7")%>">
    <input type="hidden" name="Alloy6" value="<%=Session("SphereAlloy6")%>">
    <input type="hidden" name="Alloy5" value="<%=Session("SphereAlloy5")%>">
    <input type="hidden" name="Alloy4" value="<%=Session("SphereAlloy4")%>">
    <input type="hidden" name="Alloy3" value="<%=Session("SphereAlloy3")%>">
    <input type="hidden" name="Alloy2" value="<%=Session("SphereAlloy2")%>">
    <input type="hidden" name="Alloy1" value="<%=Session("SphereAlloy1")%>">
    <input type="hidden" name="Email" value="<%=Session("Email")%>">
    </td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><div align="right"></div></td>
    <td><div align="center">
    <input type="image" name="imageField" src="placeorder-button.jpg" >
    </div></td>
    <td>&nbsp;</td>
    </tr>
    </table>

    </div></td>
    </tr>
    </table>
    </form>

    Thanks for your help

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Code:
    <SCRIPT type="text/javascript">
    
    function POvalidator()
    { 
    var obj = document.Form1;
    var isvalid='0'
    if (obj.PONumber.value == "") {
    alert("Please enter a value for the PO Number field.");
    obj.PONumber.focus();isvalid++;
    } 
    if (Form1.agree.checked == false )
    {
    alert("Tou must agree to the Terms to continue");
    isvalid++;
    }
    if(isvalid!='0'){
    return false;}
    else{return true;}
    }
    
    
    </SCRIPT>
    onsubmit="return POvalidator() ;"




    combine the two into one function. it checs for both the POnumber and the checkbox. if either one of them is not valid it adds 1 to the var isvalid. then at the end if the variable isvalid is not 0 it returns false, if it is 0 it returns true.
    Last edited by brandonH; 12-04-2006 at 12:38 AM.
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.

  • #7
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by KeithWarren View Post

    if (form1.agree.checked == false )
    .
    .
    .
    <form name="Form1" id="Form1" method="post" action="order_confirmation.asp" onsubmit="return POvalidator() && checkCheckBox()">
    Clearly you did not check for console errors.
    That should be Form1.agree not form1.agree , or more properly document.forms.Form1.agree


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •