Ladies & Gentlemen:
I have built a form that client-side validates and posts data to a CRM
beautifully in Internet Explorer (IE) 6. The problem comes in FireFox
(FF) 1.5 when everything works except the validation. In FF it posts
fine to my CRM but with no validation!
Here are snippets of my code together after taking out as much as I can
for brevity sake.
This form, when working, should be able to be filled out, client-side
validated, and then the data posts to SalesForce (our corporate CRM).
This whole process works fine in IE, just not in FF.
Please also note that I am not a programmer by trade, just a web
schmuck trying to get a form to work.
Thanks for any help you can provide.
Ken
<script Language="JavaScript" Type="text/javascript">
function My_Validator()
{
//Validation for Last Name Content
if (TheForm.first_name.value == "")
{
alert("Please enter a value for the \"first_name\" field.");
TheForm.first_name.focus();
return (false);
}
//AND MANY OTHER FIELD VALIDATIONS OMITTED HERE FOR BREVITY
return (true);
}
</SCRIPT>
<form
action="http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8"
method="POST" onsubmit="return My_Validator();" language="JavaScript"
name="TheForm">
<input type="hidden" name="lead_source" value="Web Form" />
<input type="hidden" name="Campaign_ID" value="701300000000zjq" />
<input type="hidden" name="oid" value="00D300000000FEp" />
<input type="hidden" name="retURL"
value="http://www.knowitall.com/forms/cd/response.html" />
<table border="0" cellpadding="2" style="border-collapse: collapse"
width="842" id="table2">
<tbody>
<tr>
<td width="196">First Name: </td>
<td colspan="2"> <input name="first_name" id="first_name"
type="text" size="50" maxlength="40" /><sup>*</sup></td>
</tr>
//AND MANY OTHER FIELDS OMITTED HERE FOR BREVITY
<input type="submit" name="submit" style="font-family: verdana;
font-size: 9pt" value="Send Form Now" /> </p>
</form> 6 1803
goober wrote: In FF it posts fine to my CRM but with no validation!
Hopefully this is an annoyance rather than a problem, as server-side
validation should exist also :)
if (TheForm.first_name.value == "")
You are using TheForm to refer to your form object. This is an IE trick
which makes the name TheForm available as a global variable.
Instead, you should reference the form properly.
See the instructions here for how to reference a form and its elements: http://www.javascripttoolbox.com/bestpractices/
--
Matt Kruse http://www.JavascriptToolbox.com http://www.AjaxToolbox.com
Unfortuneately, there is no server-side validation currently. There
should be some probably but honestly, I do not know how to do that.
Can anyone help out with that given the code above? --Ken
goober wrote: Unfortuneately, there is no server-side validation currently. There should be some probably but honestly, I do not know how to do that. Can anyone help out with that given the code above? --Ken
First, you should quote what you are replying to. "Above" doesn't mean
anything to most people using non-web-based news readers.
Creating server-side validation depends entirely on the technology on the
server, which would make it appropriate in a different group.
The problem with your client-side validation was pointed out in the original
reply.
--
Matt Kruse http://www.JavascriptToolbox.com http://www.AjaxToolbox.com
goober wrote: Ladies & Gentlemen:
I have built a form that client-side validates and posts data to a CRM beautifully in Internet Explorer (IE) 6. The problem comes in FireFox (FF) 1.5 when everything works except the validation. In FF it posts fine to my CRM but with no validation!
Here are snippets of my code together after taking out as much as I can for brevity sake.
This form, when working, should be able to be filled out, client-side validated, and then the data posts to SalesForce (our corporate CRM). This whole process works fine in IE, just not in FF.
Please also note that I am not a programmer by trade, just a web schmuck trying to get a form to work.
Thanks for any help you can provide.
Matt has already pointed out your main issues - the use of a form name
as a global variable and not having server-side validation also. A few
extra comments:
<script Language="JavaScript" Type="text/javascript">
Drop the language attribute, it's been deprecated for years.
function My_Validator()
It is common practice to use capital letters for function names where
the function is used as a constructor. Otherwise, use a lower case
letter. It also helps to make the name more meaningful, say:
function salesForceValidator()
{
//Validation for Last Name Content
For maintenance sake, the input named 'first_name' should probably be
for a person's first name, not their last :-)
if (TheForm.first_name.value == "")
If you are going to use an object property more than once, it is good to
keep a reference to it and use that subsequently - it is more efficient
and (usually) saves typing. If it is a persons name, you may want to
test that one or more letters were added, rather than just anything:
var form = document.TheForm;
var fName = form.first_name;
if (! /\w/.test(fName.value)) // False if at least one letter entered
{ alert("Please enter a value for the \"first_name\" field.");
You can nest double quotes inside single quotes (and vice versa). A
common practice is to use single quotes in JavaScript and double in
HTML. Also, prompt the user with the field name that they see on the
face of the form, not what you are using in the program, with language
that makes sense to them:
alert('Please enter a name in the "First Name" field.');
TheForm.first_name.focus();
It's good to test methods before using them:
if (fName.focus) fName.focus();
return (false);
There's no need for the parenthesis around 'false', it does nothing useful:
return false;
}
//AND MANY OTHER FIELD VALIDATIONS OMITTED HERE FOR BREVITY
return (true);
return true;
Usually that isn't necessary - if false isn't returned, the form will
submit.
} </SCRIPT>
<form action="http://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" onsubmit="return My_Validator();" language="JavaScript"
There is no 'language' attribute for a form. There is a 'lang'
attribute, but that is intended to specify "the base language of an
element's attribute values and text content."
The value "JavaScript" is unlikely to be useful. ;-)
<URL:http://www.w3.org/TR/html4/struct/dirlang.html#adef-lang>
name="TheForm">
<input type="hidden" name="lead_source" value="Web Form" /> <input type="hidden" name="Campaign_ID" value="701300000000zjq" /> <input type="hidden" name="oid" value="00D300000000FEp" /> <input type="hidden" name="retURL" value="http://www.knowitall.com/forms/cd/response.html" />
Unless this is XHMTL (and your attribute names make me think it isn't),
don't use ' />' for empty elements, use correct HTML: '>'
<table border="0" cellpadding="2" style="border-collapse: collapse" width="842" id="table2"> <tbody>
<tr> <td width="196">First Name: </td> <td colspan="2"> <input name="first_name" id="first_name" type="text" size="50" maxlength="40" /><sup>*</sup></td> </tr>
//AND MANY OTHER FIELDS OMITTED HERE FOR BREVITY
<input type="submit" name="submit"
Don't ever name a submit button 'submit', it will mask the form's submit
method so that you can't call it. It may not matter here, but it is bad
practice and will cause you a problem eventually.
You should only give an element a name if it needs it. There are two
main reasons to give a submit button a name:
1. You have multiple submit buttons and want to know which
one was used
2. You want to use the name to access the button
Neither case seems to apply here, so probably just remove the button's
name attribute.
[...]
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
Matt & Rob:
With your help I was able to get the form working properly in FireFox.
I also appreciate the "over and beyond" effort you have given Rob in
helping me as a non-programmer. In the upcoming months I intend to get
some basic JS classes/tutorails/books so that I can at least have a
foundation to be able to start to begin to understand how this all
works. Do you either of you have suggestions on where one would want
to start learning JS. I would like something that is relatively
hands-on instead of just readinig it all out of a book.
Again, I really appreciate your time and help, thanks!
Ken
goober wrote : Ladies & Gentlemen:
I have built a form that client-side validates and posts data to a CRM beautifully in Internet Explorer (IE) 6. The problem comes in FireFox (FF) 1.5 when everything works except the validation. In FF it posts fine to my CRM but with no validation!
Here are snippets of my code together after taking out as much as I can for brevity sake.
This form, when working, should be able to be filled out, client-side validated, and then the data posts to SalesForce (our corporate CRM). This whole process works fine in IE, just not in FF.
Please also note that I am not a programmer by trade, just a web schmuck trying to get a form to work.
Thanks for any help you can provide.
Ken
<script Language="JavaScript" Type="text/javascript">
Language is deprecated; type is both backward and forward-compatible.
Use only type.
function My_Validator() {
//Validation for Last Name Content if (TheForm.first_name.value == "")
I'm not going to repeat everything which was said but I am going to tell
you to rely on DOM 2 HTML attributes and methods which are well
supported by modern browsers (including MSIE 6 and MSIE 7): http://www.w3.org/TR/DOM-Level-2-HTML/html.html
and also to read
Using Web Standards in Your Web Pages
Accessing Elements with the W3C DOM http://www.mozilla.org/docs/web-deve...tml#dom_access
which contains all one needs to look for in order to fix this sort of
issues.
Gérard
--
remove blah to email me This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cjl |
last post by:
Hey all:
I've searched the newsgroup, and googled, but I'm stuck. I want to be
able to 'dynamically' add a .js file to a web page after the page has
loaded, based on user interaction.
For...
|
by: DavidB |
last post by:
Hi all
I have a script that works perfectly in IE but not in FF. I am sure
that the problem is easy to resolve, but I seem to be too dumb to
figure it out.
<html>
<head>
<script...
|
by: Lennart |
last post by:
Hi folks,
I have created an animated image gallery in dhtml. It works fine in
Internet Explorer. In Firefox, it only works if I ommit the DOCTYPE tag.
The page is valid xhtml-strict but with a...
|
by: Bigpond News Server |
last post by:
I have built a website that uses frames and a heavy reliance on Java Script
to modify framesets, frames and load pages on the fly. The site works fine
when using the PC version of Internet...
|
by: gray_slp |
last post by:
I am designing a web survey using surveymonkey.com and discovered I
could use javascript to modify their standard question formats much
the same as can be done in myspace.
I used this feature to...
|
by: gray_slp |
last post by:
I am designing a web survey using surveymonkey.com and discovered I
could use javascript to modify their standard question formats much
the same as can be done in myspace.
I used this feature to...
|
by: Larry |
last post by:
The below script, I have been using for many years, stopped working in IE 7.0 all of a sudden.
It works using NS and Firefox.
Anyone know why this is? Did something change in IE 7.0 that may be...
|
by: sachinmanath |
last post by:
i have a code which works in internet explorer but not in firefox. I have a page with several thumbnails. Above these thumbnails I placed a large picture. So, when you click a thumb, the large pic...
|
by: sj071 |
last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days...
The Problem:
I have a javascript file that uses...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |