Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » JavaScript

getElementById ignored by Firefox

 
Jump to:  
 
GarryJones
PostPosted: Fri Sep 05, 2008 8:58 pm    Post subject: 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?
 

 
Gregor Kofler
PostPosted: Fri Sep 05, 2008 8:58 pm    Post subject: Re: getElementById ignored by Firefox
       
GarryJones meinte:
Quote:
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



--
LINK ::: Landschafts- und Reisefotografie
LINK ::: meine JS-Spielwiese
LINK ::: Bildagentur für den alpinen Raum
 

 
Gregor Kofler
PostPosted: Fri Sep 05, 2008 8:58 pm    Post subject: Re: getElementById ignored by Firefox
       
GarryJones meinte:

Quote:
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


--
LINK ::: Landschafts- und Reisefotografie
LINK ::: meine JS-Spielwiese
LINK ::: Bildagentur für den alpinen Raum
 

 
GarryJones
PostPosted: Fri Sep 05, 2008 10:09 pm    Post subject: Re: getElementById ignored by Firefox
       
On 5 Sep, 23:13, Gregor Kofler <use...@gregorkofler.at> wrote:
Quote:
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").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
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

HP 83 Magenta UV Value Pack Wierszyki noworoczne gry i zabawy iso 9001 Portal Miasteczko kujawsko-pomorskie