By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

getElementById ignored by Firefox

P: n/a
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?

Sep 5 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 5 '08 #2

P: n/a
On 5 Sep, 23:13, Gregor Kofler <use...@gregorkofler.atwrote:
GarryJones meinte:
The following works in MSIE but not firefox.
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").selectedIn dex=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").selectedIn dex=0;
document.getElementsByName("tavfnmkas").value="";
document.getElementsByName("tavfnmkas").focus()
}

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

Any help appreciated!

Garry Jones
Sweden
Sep 5 '08 #3

P: n/a
GarryJones meinte:
document.getElementsByName("grant_ask").selectedIn dex=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
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Sep 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.