Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rohan 105 posts 162 karma points
    Sep 29, 2014 @ 16:15
    Rohan
    0

    execute java script validation with BeginUmbracoForm methods

    Hi

    I need to use some java script validation in one of my form. Below is the form coding. I am using surface controller in MVC. 

    So once i click on submit button (Customer Checkout), it will check "First Name" is entered or not. If not entered then it should no submit the form.

    If there is a simple webform then i can do this easily but don't know how to do it with BeginUmbracoForm. Please help me here ?

    @using (Html.BeginUmbracoForm("CheckOutCustomerOverview", "CustomerSurface", FormMethod.Post))
        {
            @*<script type="text/javascript" language="javascript">
                function validateForm(formElement)
                {
                    if(formElement.billingFirstnames.Length <= 0)
                    {
                        alert('Please enter First Name');
                        return false;
                    }
                }
            </script>*@
            <table class="formTable">
    
                <tr>
                    <td class="fieldLabel">
                        First Name(s):
                    </td>
                    <td class="fieldData">
                        <input name="billingFirstnames" id="billingFirstnames" type="text" maxlength="20" value=""
                               style="width: 200px;">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Customer Checkout" onclick="return validateForm(this.form)" />
                    </td>
                </tr>
            </table>
        }

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Sep 30, 2014 @ 15:24
    Andy Butland
    0

    Looks like it should work OK except in JavaScript "length" is lowercase.  

    Andy

Please Sign in or register to post replies

Write your reply to:

Draft