getElementById ignored by Firefox

G

GarryJones

The following works in MSIE but not firefox.

I suspect it has something to do with the fact that the element I am
trying to access is not the "tid" which is the name of the DIV that is
passed to this javascript. The function is a "show/hide" for a form. I
want to ensure that any possible previously entered value is cleared
so the user starts with an empty field with focus.

I have tried to ways, with naming and getElementById but in both
cases any entry is left standing and the focus is not passed in
firefox, whilst both work fine in MSIE.

First attempt (with getElementById)

function InsertContentshowgruppanm(tid) {
if( document.getElementById(tid).style.display == "none") {
document.getElementById(tid).style.display = "block";
document.getElementById("grant_ask").selectedIndex=0;
document.getElementById("tavfnmkas").value="";
document.getElementById("tavfnmkas").focus()
}

else {
document.getElementById(tid).style.display = "none";
}
}


Second attempt (with name of form inserted)

function InsertContentshowgruppanm(tid) {
if( document.getElementById(tid).style.display == "none") {
document.getElementById(tid).style.display = "block";
document.getElementById("grant_ask").selectedIndex=0;
document.prel_svlmst_grpcol.tavfnmkas.focus()
}
else {
document.getElementById(tid).style.display = "none";
}
}


So obvious question. Whats the syntax for firefox?
 
G

Gregor Kofler

GarryJones meinte:
The following works in MSIE but not firefox.

I suspect it has something to do with the fact that the element I am
trying to access is not the "tid" which is the name of the DIV that is
passed to this javascript. The function is a "show/hide" for a form.

[snip]

DIVs don't have names. Forms and their elements have.

Anyway, your "problem" has been asked and answered hundreds of times
before. MSIE automatically (and wrongly) populates the id property of
elements with the same value of the name property, hence you can access
form elements with names via gEBI() - but only in IE. gEBI() needs
explicitly set (unique) ids. Otherwise resort to getElementsByName() -
note the plural.

Gregor
 
G

GarryJones

GarryJones meinte:

DIVs don't have names. Forms and their elements have.

Still no go I am afraid....

Let me explain. The DIV has an ID and the first 2 rows of code either
display or hide the DIV which is correctly called by its id. Now, in
that DIV is a form. And on that form there are some elements which
have names. When the user clicks the link which fires this code it is
supposed to empty any previously entered value.

What I want is for the form to start with focus in the tavfnmkas
field. This field should be empty so any left over data from previous
viewings should be cleaned out when the button is clicked and the DIV
(with the form) toggles status "none" to status "block" and becomes
visible.

What these three "document.getElementsByName" lines should do is

document.getElementsByName("grant_ask").selectedIndex=0; //SHOULD set
the selected option index to zero in a SELECT
document.getElementsByName("tavfnmkas").value=""; //SHOULD removed any
previously entered data from the field tavfnmkas
document.getElementsByName("tavfnmkas").focus() //SHOULD place focus
in the field tavfnmkas

"None of the above" is the result of my competence and understanding
of this. I am very gratefull of any further help anyone would like to
provide.

My latest attempt using getElementsByName
***********************************************
function InsertContentshowgruppanm(tid) {
if( document.getElementById(tid).style.display == "none") {
document.getElementById(tid).style.display = "block";
document.getElementsByName("grant_ask").selectedIndex=0;
document.getElementsByName("tavfnmkas").value="";
document.getElementsByName("tavfnmkas").focus()
}

else {
document.getElementById(tid).style.display = "none";
}
}

Any help appreciated!

Garry Jones
Sweden
 
G

Gregor Kofler

GarryJones meinte:
document.getElementsByName("grant_ask").selectedIndex=0;
document.getElementsByName("tavfnmkas").value="";
document.getElementsByName("tavfnmkas").focus()

getElementsByName() returns a collection (didn't I mention the plural?),
therefore you need document.getElementsByName("...")[0].propertyOrMethod.

Gregor
 

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

Similar Threads


Members online

Forum statistics

Threads
474,002
Messages
2,570,257
Members
46,857
Latest member
ArleenWill

Latest Threads

Top