2

I have used several custom fields in my web to lead form ,and wanna add validation rules to my html form as well.How to achieve such validations.So far,what I 've tried using javascript is enclosed below.But this code is not working as expected,it is not showing any alerts or so.

<body>
    <form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" onsubmit="return ValidateForm()">
        <input type=hidden name="oid" value="00Dm00000008iPU"/>
        <input type=hidden name="retURL" value="http://www.google.com"/>

Fields that I wanna make required:

<table width="100%" border="0">
    <tbody>
        <tr>
            <td width="24%" align="right">
                MerchantID:
            </td>
            <td width="1%">&nbsp;</td>
            <td width="25%">
                <input  id="00Nm0000001ABCv" maxlength="20" name="00Nm0000001ABCv" size="20" type="text" />
            </td>
            <td width="24%" align="right">
                Sales Office Name:
            </td>
            <td width="2%">&nbsp;</td>
            <td width="24%">
                <input  id="00Nm0000001ABDA" maxlength="50" name="00Nm0000001ABDA" size="20" type="text" />
            </td>
        </tr>

My Validation javascript :

<script type='text/javascript'>
    function ValidateForm() {
        var helperMsg = '';

        if (document.getElementById("00Nm0000001ABCv").value.length == 0) {
            helperMsg += "Please enter Merchant ID \n\r";
        }
        if (helperMsg.length > 0) {
            alert(helperMsg);
            return false;
        }
        return true;
    }
</script>

Please help me out in this.

3

I highly recommend you save yourself a lot of trouble and don't try to "reinvent the wheel". Instead, go and download the free jQuery Validation Plugin. Here are some links to a couple of related posts you may find helpful with some tips on how to implement it:

Wes Nolte's Blog The Silver Lining and on Stack Overflow: https://stackoverflow.com/questions/20928470/jquery-validate-plugin-how-to-show-different-error-messages-based-on-various-c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.