473,405 Members | 2,310 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,405 software developers and data experts.

getElementById ignored by Firefox

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
3 2042
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Dave Hammond | last post by:
Hi All, The following code works in IE but not Firefox. IE produces the expected "this is more text!" output, but Firefox produces "no more text". Any ideas why? <BODY> <FORM> <INPUT...
1
by: Muffinman | last post by:
Howdy, I've got here a sample of my function which is supposed to fade a certain piece of text to another colour. This line is then located in a for loop and it works pretty well in IE 6....
5
by: Derek Erb | last post by:
I am banging my head against the wall with this one. The following code snippets work perfectly fine in MSIE6. But produce an error in Firefox and do not work at all. BROWSER.HTM <HTML> .......
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
5
by: Andrea | last post by:
I am trying to alter css using javascript as well as use the innerHTML function. I have pasted below 3 forms that access getElementById in slightly different ways (I wanted to rule out that it was...
4
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6...
1
by: Zhang Weiwu | last post by:
Hello. I know a lot of different ways to write css that work for IE but ignored by Fx, but is there a way to let IE process XSLT but leaving Fx completely ignore the XSLT? The classic filter...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
1
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.