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.

    <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">
            <td width="24%" align="right">
            <td width="1%">&nbsp;</td>
            <td width="25%">
                <input  id="00Nm0000001ABCv" maxlength="20" name="00Nm0000001ABCv" size="20" type="text" />
            <td width="24%" align="right">
                Sales Office Name:
            <td width="2%">&nbsp;</td>
            <td width="24%">
                <input  id="00Nm0000001ABDA" maxlength="50" name="00Nm0000001ABDA" size="20" type="text" />

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) {
            return false;
        return true;

Please help me out in this.

1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .