Connecting Tech Pros Worldwide Forums | Help | Site Map

JavaScript Validation Works In Firefox But Not IE

SJ Carter
Guest
 
Posts: n/a
#1: Jun 27 '08
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.

Joost Diepenmaat
Guest
 
Posts: n/a
#2: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


SJ Carter <sjmcarter@gmail.comwrites:
Quote:
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/
Joost Diepenmaat
Guest
 
Posts: n/a
#3: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


Joost Diepenmaat <joost@zeekat.nlwrites:
Quote:
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/
SJ Carter
Guest
 
Posts: n/a
#4: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
Joost Diepenmaat <jo...@zeekat.nlwrites:
Quote:
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.
Joost Diepenmaat
Guest
 
Posts: n/a
#5: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


SJ Carter <sjmcarter@gmail.comwrites:
Quote:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
>Joost Diepenmaat <jo...@zeekat.nlwrites:
Quote:
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/
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#6: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


SJ Carter wrote:
Quote:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
>Joost Diepenmaat <jo...@zeekat.nlwrites:
Quote:
>>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.
Quote:
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
SJ Carter
Guest
 
Posts: n/a
#7: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


On May 14, 4:00 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
SJ Carter wrote:
Quote:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
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
>
Quote:
Thanks Joost, but it still isn't working.
>
Post the error message, then.
>
Quote:
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!
SAM
Guest
 
Posts: n/a
#8: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


SJ Carter a écrit :
Quote:
On May 14, 3:30 pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
>Joost Diepenmaat <jo...@zeekat.nlwrites:
Quote:
>>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
GTalbot
Guest
 
Posts: n/a
#9: Jun 27 '08

re: JavaScript Validation Works In Firefox But Not IE


On 14 mai, 18:36, SJ Carter <sjmcar...@gmail.comwrote:
Quote:
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
Closed Thread