473,856 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 InsertContentsh owgruppanm(tid) {
if( document.getEle mentById(tid).s tyle.display == "none") {
document.getEle mentById(tid).s tyle.display = "block";
document.getEle mentById("grant _ask").selected Index=0;
document.getEle mentById("tavfn mkas").value="" ;
document.getEle mentById("tavfn mkas").focus()
}

else {
document.getEle mentById(tid).s tyle.display = "none";
}
}
Second attempt (with name of form inserted)

function InsertContentsh owgruppanm(tid) {
if( document.getEle mentById(tid).s tyle.display == "none") {
document.getEle mentById(tid).s tyle.display = "block";
document.getEle mentById("grant _ask").selected Index=0;
document.prel_s vlmst_grpcol.ta vfnmkas.focus()
}
else {
document.getEle mentById(tid).s tyle.display = "none";
}
}
So obvious question. Whats the syntax for firefox?

Sep 5 '08 #1
3 2067
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 getElementsByNa me() -
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...@gregork ofler.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.getEl ementsByName" lines should do is

document.getEle mentsByName("gr ant_ask").selec tedIndex=0; //SHOULD set
the selected option index to zero in a SELECT
document.getEle mentsByName("ta vfnmkas").value =""; //SHOULD removed any
previously entered data from the field tavfnmkas
document.getEle mentsByName("ta vfnmkas").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 getElementsByNa me
*************** *************** *************** **
function InsertContentsh owgruppanm(tid) {
if( document.getEle mentById(tid).s tyle.display == "none") {
document.getEle mentById(tid).s tyle.display = "block";
document.getEle mentsByName("gr ant_ask").selec tedIndex=0;
document.getEle mentsByName("ta vfnmkas").value ="";
document.getEle mentsByName("ta vfnmkas").focus ()
}

else {
document.getEle mentById(tid).s tyle.display = "none";
}
}

Any help appreciated!

Garry Jones
Sweden
Sep 5 '08 #3
GarryJones meinte:
document.getEle mentsByName("gr ant_ask").selec tedIndex=0;
document.getEle mentsByName("ta vfnmkas").value ="";
document.getEle mentsByName("ta vfnmkas").focus ()
getElementsByNa me() returns a collection (didn't I mention the plural?),
therefore you need document.getEle mentsByName(".. .")[0].propertyOrMeth od.

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
1914
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 TYPE=HIDDEN NAME="moreText" VALUE="<PRE>This is more text!</PRE>">
1
3430
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. However, in Firefox, and thus I assume it will be the same in Netscape and Mozilla, it gives a problem with the: getElementById('main_txt'). Due to that in setTimeout("",) it requires the "" signes and thus I can not use the same ones in the getElement...
5
31230
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> .... <div class="Abb"> <h2 id="ABTit">BROWSER</h2> </div>
3
9282
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 work on FireFox or Netscape. What could be wrong? The function: function setActiveTab(tabNo) {
5
4346
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 the method.) All 3 work fine on IE but only work momentarily on Firefox. For example, one form has text that changes from red to black when the user clicks the button. In IE it changes. In Firefox it changes for a split second then goes back...
4
2675
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 but is a dead fish in FireFox. There is no support offered on the site where it came from. I'd really appreciate help with this as it will not only to get it working but to learn how it all works so I can add it to my repertoire. Thanks!
1
1845
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 doesn't seem to work: <!--><?xml-stylesheet type="text/xsl" href="my.xsl"?><!--> The above seems to be ignored by both IE and Firefox P.S. In the beginning I thought finding something that works for IE but not
13
4973
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 internet. When I run Firebug on it, it says: document.getElementById("TICKER") has no properties TICKER_CONTENT = document.getElementById("TICKER").innerHTML; Here is the complete script:
1
2245
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 script to update the display to the user depending on what they choose (qty, options, shipping etc.) I'm sure it's simple but I could really use a hand. Thanks!!
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10693
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10773
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10378
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9527
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5756
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4170
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.