function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ForceComForceCom 

Java Script Validation---Help...

We have a custom field in Sales Force and a have a simple web-to-lead form on our website that uses ringlead to pass the lead to Sales Force.

The Custom ID and Name that Sales Force gave us for inclusion on this form (to be attached to the ‘region’ field) is:

0N30000000mnNj

This is a nightmare for clientside javacript/ajax validation as

IT IS NOT WEB COMPLIENT – name an id should not begin with a digit, should begin only with a letter. please see W3 ‘s website:

http://www.w3.org/TR/html401/types.html#type-id

This is a serious problem as I am unable to write ANY JavaScript validation for this field and subsequently data is lost and leads are not being distributed correctly which is harming our business. Why could sales force not spot this and is there a way to customise this custom field name and id so that at least it starts with a letter???

Has anyone come against this issue and found a work-around in JavaScript validation???

 

Any help would be greatly appreciated...

 

Thanks


MJ09MJ09

I'm assuming you've got HTML code like this:

 

 

<form name="myForm">
<input type="text" name="0N30000000mnNj" id="" id="0N30000000mnNj" value="" />

 

and you're using JavaScript code like this to get whatever value the user has entered into this field:

 

 

var theValue = document.myForm.0N30000000mnNj.value;

 

 

Instead, use something like this:

 

 

var theValue = document.getElementById('0N30000000mnNj').value;

 Since you're putting the Id in quotes, it doesn't matter that it starts with a number.

 

Of course, if hte above isn't what you're doing, it might help if you posted the code you're trying to use....

 

ForceComForceCom

Hi

 

Thank you So much, I appreciate your reply.

Please find below my code.

 

 

<form>
variable interest = document.getElementById('0N30000000mnNj').value;
 
if(form.interest.value == '') {
alert('Please select your Program of Interest');
form.interest.focus();
return false;
}

 

 

 

MJ09MJ09

Without seeing all of the relevant HTML code, it's a little hard to tell you exactly what to do, but I think the issue is that you need to understand the distinction between HTML tags in your code and the JavaScript representations of them.

 

<form name="myForm">
<input type="text" name="0N30000000mnNj" id="" id="0N30000000mnNj" value="" />

Above is an HTML form named "myForm," with an HTML input tag that has the same name and id. There are two ways to access that input tag in JavaScript. One is using the name, and taking advantage of the fact that the document has an element named "myForm" (the form tag) and myForm has an element named "0N30000000mnNj." To write JavaScript to get the value of that input tag and put it into a variable named theValue, you might say this:

 

 

var theValue = document.myForm.0N30000000mnNj.value;

 (Note that it starts with "var," not "variable" as your code sample said.)

 

However, the above won't work, because the element's name starts with a digit. So instead, you can use the second way. The second way calls a built-in JavaScript method named getElementById() that says, "find the HTML element with a particular id," and looks like this:

 

 

var theValue = document.getElementById('0N30000000mnNj').value;

This way uses the HTML input tag's id to find the element, get its value, and put the result in a JavaScript variable named theValue.

 

 

Note that JavaScript is case sensitive, so you have to use upper and lower case exactly as given above.

 

FWIW, this is all pure JavaScript -- there's really nothing Salesforce-y about it.

 

Good luck!

 

 

 

 

ForceComForceCom

Hi 

 

I really appreciate your reply, but I already did what you suggested but it does come through.Please find below the html code and java script code.

 

Java script:

 

 

<script language="javascript">

 

function validate(form) {

 

if(form.first_name.value == '') {

 

alert('Please enter your first name');

form.first_name.focus();

return false;

}

 

if(form.last_name.value == '') {

 

alert('Please enter your last name');

form.last_name.focus();

return false;

}

 

if (form.email.value == '') {

        alert("You didn't enter an email address.\n");

        form.email.focus();

       return false;

    } 

 

if(form.country.value == '') {

 

alert('Please enter your country');

form.country.focus();

return false;

}

 

var stripped = phone.value.replace(/[\(\)\.\ ]/g, '');     

 

if (form.phone.value =='') {

        alert("Please enter your phone number.\n");

       form.phone.focus();

   return false;

}  

else if (isNaN(parseInt(stripped))) {

       alert("The phone number contains illegal characters.\n");

        form.phone.focus();

        return false;

 } 

 else if (!(stripped.length == 12)) {

        alert("The phone number is the wrong length. Make sure you included an country code in the format Country Code-xxx-xxx-xxxx.\n");

        form.phone.focus();

        return false

 }       

 

var interest = document.getElementById('00NA00000076xL2');

if(form.interest.value == '') {

alert('Please select your Program of Interest');

form.interest.focus();

return false;

}

 

  return true;

}

 

</script>

 

 

HTML:

 

 

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <META> element to your page <HEAD>.      -->
<!--  If necessary, please modify the charset parameter to specify the        -->
<!--  character set of your HTML page.                                        -->
<!--  ----------------------------------------------------------------------  -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"></meta>
<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: Please add the following <FORM> element to your page.             -->
<!--  ----------------------------------------------------------------------  -->
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" onsubmit="return validate(this);javascript&colon;captureResponse(this);">
<fieldset class="contact">
<input type="hidden" name="oid" value="00DA00000009MZJ"/>
<input type="hidden" name="retURL" value="http://cusv.force.com/apex/thankyou"/>
<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements.  Please uncomment   -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="msatin@enrollmentrx.com">                                        -->
<!--  ----------------------------------------------------------------------  -->
<div>
<label for="first_name">First Name<em>*</em></label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br/>
</div>
<div>
<label for="last_name">Last Name<em>*</em></label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br />
</div>
<div>
<label for="email">Email<em>*</em></label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br />
</div>
<div>
<input type="hidden"   id="company" maxlength="40" name="company" size="20" value="CUSV"/>
</div>
<div>
<input type="hidden" name="sfga" value="00DA00000009MZJ"/>
</div>
<div>
<label for="street"> Street Address</label><input  id="street" maxlength="80" name="street" size="20" type="text" />
</div>
<div>
<label for="city">Mailing City</label><input  id="city" maxlength="40" name="city" size="20" type="text" />
</div>
<div>
<label for="state">Mailing State</label><input  id="state" maxlength="20" name="state" size="20" type="text" />
</div>
<div>
<label for="zip">Mailing Zip</label><input  id="zip" maxlength="20" name="zip" size="20" type="text" />
</div>
<div>
<label for="country">Mailing Country<em>*</em></label><input  id="country" maxlength="40" name="country" size="20" type="text" />
</div>
<div>
<label for="phone">Phone<em>*</em></label><input  id="phone" maxlength="40" name="phone" size="20" type="text" />
</div>
<div>
<label for="Program of Interest">Program of Interest:<em>*</em></label><select  id="00NA00000076xL2" name="00NA00000076xL2" title="Program of Interest"><option value="">--None--</option><option value="Certificate Programs">Certificate Programs</option>
<option value="MBA">MBA</option>
<option value="MS/MBA Combination">MS/MBA Combination</option>
<option value="MS Computer Engineering">MS Computer Engineering</option>
<option value="MS Computer Science">MS Computer Science</option>
</select>
</div>

 

MJ09MJ09

Change

 

 

var interest = document.getElementById('00NA00000076xL2');
if(form.interest.value == '') {
  alert('Please select your Program of Interest');
  form.interest.focus();
  return false;
}

 

 

to:

 

 

var interest = document.getElementById('00NA00000076xL2');
if(interest.value == '') {
  alert('Please select your Program of Interest');
  interest.focus();
  return false;
}

 The first statement defines a JavaScript variable named "interest" and sets it up to refer to the HTML element. The second statement compares the value of that variable to an empty string.

 

Your version of the code wasn't ever referencing the JavaScript variable.