Accessing a field value by ID in Firefox

E

effendi

I amtrying to rewrite this code to be compliant tofirefox and MSIE.This
works fine inMSIE

if (thisForm.AttachmentCount.value==0) {
attachment=thisForm.all["Attachment"].value
if(attachment!="")
{
attachment=attachment.split(".")
if ((attachment[attachment.length-1])!="doc")
{alert("Please attach your minutes in MS Word format only")
thisForm.SubmissionCheck.value=""
return false}
}
}

The line--> attachment=thisForm.all["Attachment"].value does not work
in Firefox. I tried to change it to
attachment=thisForm.getElementById('Attachment').value but its ooes
work either. How do I change it?

Thanks
 
R

RobG

I amtrying to rewrite this code to be compliant tofirefox and MSIE.This
works fine inMSIE

if (thisForm.AttachmentCount.value==0) {

What is "thisForm"? Is it the name or ID of a form element? If so,
read:

<URL: http://www.jibbering.com/faq/#FAQ4_41 >

The simplest solution is to create a local variable that masks IE's
global variable and gives all browsers access to the form. Insert the
following before the if statement:

var thisForm = document.forms['thisForm'];

attachment=thisForm.all["Attachment"].value

Form elements don't have an "all" method (well, maybe in IE the do), so
guessing that you are trying to get access to a form control called
"Attachment" (and keeping the variable "attachment" local to the
function):

var attachment = thisForm["Attachment"].value

if(attachment!="")
{
attachment=attachment.split(".")
if ((attachment[attachment.length-1])!="doc")

A better test is to ditch split and use a regular expression to see if
the filename ends in .doc:

if ( ! /\.doc$/.test(attachment) ) {
/* filename doesn't end in .doc */
{alert("Please attach your minutes in MS Word format only")

Noting that the fact that whether a filename has or hasn't a .doc
extension is no guarantee that it is or isn't a Word file. What about
..rtf? What about Office 2007 XML fomats? Word files saved in that
format end (by default) in .docx. Are PDF's forbidden too? Or plain
text? It seems a rather silly restriction.
 
E

effendi

RobG said:
I amtrying to rewrite this code to be compliant tofirefox and MSIE.This
works fine inMSIE

if (thisForm.AttachmentCount.value==0) {

What is "thisForm"? Is it the name or ID of a form element? If so,
read:

<URL: http://www.jibbering.com/faq/#FAQ4_41 >

The simplest solution is to create a local variable that masks IE's
global variable and gives all browsers access to the form. Insert the
following before the if statement:

var thisForm = document.forms['thisForm'];

attachment=thisForm.all["Attachment"].value

Form elements don't have an "all" method (well, maybe in IE the do), so
guessing that you are trying to get access to a form control called
"Attachment" (and keeping the variable "attachment" local to the
function):

var attachment = thisForm["Attachment"].value

if(attachment!="")
{
attachment=attachment.split(".")
if ((attachment[attachment.length-1])!="doc")

A better test is to ditch split and use a regular expression to see if
the filename ends in .doc:

if ( ! /\.doc$/.test(attachment) ) {
/* filename doesn't end in .doc */
{alert("Please attach your minutes in MS Word format only")

Noting that the fact that whether a filename has or hasn't a .doc
extension is no guarantee that it is or isn't a Word file. What about
.rtf? What about Office 2007 XML fomats? Word files saved in that
format end (by default) in .docx. Are PDF's forbidden too? Or plain
text? It seems a rather silly restriction.

thisForm.SubmissionCheck.value=""
return false}
}
}

Rob

Thanks, I read the link and what you say is consistent with what was
written in there. I ried it and the code stopped working complete -
both in IE and Firefox. Do you have any idea what could caused that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top