473,396 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JavaScript Validation Works In Firefox But Not IE

Hello guys,

I have the following piece of code:
function validate()
{
var f = document.form1;
if (f.name.value == "" || f.name.value == '' || f.name.value.length
== 0)
{
alert('Please enter your name');
return false;
}
return true;
}
It works fine in Firefox, and when I use firebug to inspect the code I
don't get any errors. However, it doesn't work for IE. Any reasons
for that, and how can I fix this problem? Thanks.
Jun 27 '08 #1
8 1548
SJ Carter <sj*******@gmail.comwrites:
Hello guys,

I have the following piece of code:
function validate()
{
var f = document.form1;
if (f.name.value == "" || f.name.value == '' || f.name.value.length
== 0)
{
alert('Please enter your name');
return false;
}
return true;
}
It works fine in Firefox, and when I use firebug to inspect the code I
don't get any errors. However, it doesn't work for IE. Any reasons
for that, and how can I fix this problem? Thanks.
You probably really shouldn't have a form element named "name".

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #2
Joost Diepenmaat <jo***@zeekat.nlwrites:
You probably really shouldn't have a form element named "name".
or if you do, you can probably use form.elements.name.value instead of
form.name.value

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #3
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Joost Diepenmaat <jo...@zeekat.nlwrites:
You probably really shouldn't have a form element named "name".

or if you do, you can probably use form.elements.name.value instead of
form.name.value

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
Thanks Joost, but it still isn't working. I tried changing the form
element name with no success, and then tried using the
"form.elements....", with identical results.
Jun 27 '08 #4
SJ Carter <sj*******@gmail.comwrites:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
>Joost Diepenmaat <jo...@zeekat.nlwrites:
You probably really shouldn't have a form element named "name".

or if you do, you can probably use form.elements.name.value instead of
form.name.value

Thanks Joost, but it still isn't working. I tried changing the form
element name with no success, and then tried using the
"form.elements....", with identical results.
it'd probably help if you post a link to the complete page.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #5
SJ Carter wrote:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
>Joost Diepenmaat <jo...@zeekat.nlwrites:
>>You probably really shouldn't have a form element named "name".
or if you do, you can probably use form.elements.name.value instead of
form.name.value

Thanks Joost, but it still isn't working.
Post the error message, then.
I tried changing the form element name with no success, and then tried
using the "form.elements....", with identical results.
DOM terms collide with markup terms here. Just to clarify, you should not
have a form *control* named "name", i.e. you should not have

<input name="name" ...>

because the form *element*

<form ... name="foo">
...
</form>

would then cause formRef.name to be evaluated to "foo" instead of the input
object. Modifying or removing the `name' attribute value of the `form'
element would not change that, which could explain what you observed.

You have to change the value of the `name' attribute of the `input' element
instead. BTW, "submit" is another name that should be avoided, as form
objects have a submit() method.

Please trim your quotes.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jun 27 '08 #6
On May 14, 4:00 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
SJ Carter wrote:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Joost Diepenmaat <jo...@zeekat.nlwrites:
You probably really shouldn't have a form element named "name".
or if you do, you can probably use form.elements.name.value instead of
form.name.value
Thanks Joost, but it still isn't working.

Post the error message, then.
I tried changing the form element name with no success, and then tried
using the "form.elements....", with identical results.

DOM terms collide with markup terms here. Just to clarify, you should not
have a form *control* named "name", i.e. you should not have

<input name="name" ...>

because the form *element*

<form ... name="foo">
...
</form>

would then cause formRef.name to be evaluated to "foo" instead of the input
object. Modifying or removing the `name' attribute value of the `form'
element would not change that, which could explain what you observed.

You have to change the value of the `name' attribute of the `input' element
instead. BTW, "submit" is another name that should be avoided, as form
objects have a submit() method.

Please trim your quotes.

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Got it working. Turns out it wasn't even that function itself, but
some embedded object that was messing things up. Thanks for all your
help!
Jun 27 '08 #7
SAM
SJ Carter a écrit :
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
>Joost Diepenmaat <jo...@zeekat.nlwrites:
>>You probably really shouldn't have a form element named "name".
or if you do, you can probably use form.elements.name.value instead of
form.name.value

Thanks Joost, but it still isn't working. I tried changing the form
element name with no success, and then tried using the
"form.elements....", with identical results.

Give another name than 'name' to your element would fix the trouble.

but the right use to get an element named 'name' and from the form named
'form1' is :

document.forms['form1'].elements['name']
or :
document.form1['name']

It is aways a good idea to do not use generic terms to name something
(here 'name' is an attribute and IE can misunderstand of what name you talk)

--
sm
Jun 27 '08 #8
On 14 mai, 18:36, SJ Carter <sjmcar...@gmail.comwrote:
Thanks Joost, but it still isn't working. I tried changing the form
element name with no success, and then tried using the
"form.elements....", with identical results.
Using Web Standards in your Web Pages
Accessing Elements with the W3C DOM
http://developer.mozilla.org/en/docs...th_the_W3C_DOM

will for sure give you the help you are seeking.

Gérard
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Blair | last post by:
Hi, I have a problem with our intranet, we are planning to install Firefox instead of Internet Explorer onto some new PCs. However, we can't get the following JavaScript to work in Firefox and...
7
by: Ryan Ternier | last post by:
We're running a site that has required field validation on the login page. It works fine on our development / test machines. However, when I upload this site to our live server i get this error. ...
4
by: Andre | last post by:
Hi, I have read at many place that .Net 2.0 was suppose to support client-side validation in non-IE Browser. But i've try a very simple validation, and firefox is unable to run it, it works only...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
by: goga | last post by:
Hi there, The following simple validation code works in internet explorer but doesn't in firefox. Specifically, in firefox shows the alert message and then loads the action page anyway. Any...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
6
by: davidiwharper | last post by:
Hi there. I'm putting together a page to collect some information from our website users and send the administrator an email. To this end I have some Javascript form validation in an external...
5
by: cbs7 | last post by:
Hi all I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2.js which I downloaded from the...
3
by: goldenv | last post by:
Hi all, I have worked an open source javascript + html page that has the potential to replace your existing browser home page. If you are interested in trying it out, or learning more about it, it...
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.