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

id and problem in Firefox

In IE, I could be able to directly refer the "id", but it isn't
possible in Firefox. Somewhere I read the solution is to refer the id
like document.getElementById("month") in Firefox. If I do so, the
script works well in Firefox, but IE throws error. (I have added the
code snippet below).

So, my question is: is there anyway to make the script work in all
browser *without* any browser fix ie, without adding any browser
detection check? Is this behavior is only for Firefox or any other
browsers also work like this (I don't have access to many browsers to
test)? TIA

<snippet>

<HEAD>
<SCRIPT LANGUAGE=javascript>
<!--
function PopulateMonths()
{
//month is id used with select
//month = document.getElementById("month"); //<-- for Firefox
month.options.length = 0; //clear options
for(var i=1; i<=12; ++i)
{
opt = new Option();
opt.text = i;
opt.value = i;
month.options[i-1] = opt;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<!--month options-->
<SELECT name="month" id="month">
</SELECT>
<!--calling script-->
<SCRIPT>
PopulateMonths(); //calling populate for the above options
</SCRIPT>
</BODY>

</snippet>

--
Email: rrjanbiah-at-Y!com
Jul 23 '05 #1
6 2454
R. Rajesh Jeba Anbiah wrote:
In IE, I could be able to directly refer the "id", but it isn't
possible in Firefox. Somewhere I read the solution is to refer the id
like document.getElementById("month") in Firefox. If I do so, the
script works well in Firefox, but IE throws error. (I have added the
code snippet below).
<snip> <HEAD>
<SCRIPT LANGUAGE=javascript>
<!--
function PopulateMonths()
{
//month is id used with select
//month = document.getElementById("month"); //<-- for Firefox
month.options.length = 0; //clear options
for(var i=1; i<=12; ++i)
{
opt = new Option();
opt.text = i;
opt.value = i;
month.options[i-1] = opt;
}
} <snip> <SELECT name="month" id="month">
</SELECT>
<!--calling script-->
<SCRIPT>
PopulateMonths(); //calling populate for the above options
</SCRIPT>


Odd, similar works OK for me across both IE and Firefox. Maybe IE is getting
upset because your assigning the widget to a variable with the same name as
an HTML Element in the same DOM scope? Try enclosing the select in
<form>...</form> or change the JS variable name.

HTH

C.
Jul 23 '05 #2
R. Rajesh Jeba Anbiah wrote:
In IE, I could be able to directly refer the "id", but it isn't
possible in Firefox. Somewhere I read the solution is to refer the id
like document.getElementById("month") in Firefox. If I do so, the
script works well in Firefox, but IE throws error. (I have added the
code snippet below). [snip]

<snippet>

<HEAD>
<SCRIPT LANGUAGE=javascript>
<!--
function PopulateMonths()
{
//month is id used with select
//month = document.getElementById("month"); //<-- for Firefox
month.options.length = 0; //clear options
for(var i=1; i<=12; ++i)

[snip]

I have no problem using code like yours in MSIE - perhaps you have an
older version of IE where the problem arises? Certainly in modern
versions, the W3C standard DOM and object methods like getElementById
sholud work perfectly well.

Don't bother to "detect browsers" though - check the objects and methods
themselves so you can do something like:-

if (document.getElementById) month = document.getElementById ("month")
else {
if (document.all && <your MSIE object/method>) {
// do MSIE code here
}
}
Jul 23 '05 #3
> <SELECT name="month" id="month">

Also, I'd make these variables different.

Robert
Jul 23 '05 #4
DU
R. Rajesh Jeba Anbiah wrote:
In IE, I could be able to directly refer the "id", but it isn't
possible in Firefox. Somewhere I read the solution is to refer the id
like document.getElementById("month") in Firefox. If I do so, the
script works well in Firefox, but IE throws error. (I have added the
code snippet below).

So, my question is: is there anyway to make the script work in all
browser *without* any browser fix ie, without adding any browser
detection check? Is this behavior is only for Firefox or any other
browsers also work like this (I don't have access to many browsers to
test)? TIA

<snippet>

<HEAD>
<SCRIPT LANGUAGE=javascript>
<script type="text/javascript">
<!--
function PopulateMonths()
{
//month is id used with select
But you also use name="month" in your code. So, there is a confusion
already here.
//month = document.getElementById("month"); //<-- for Firefox
month.options.length = 0; //clear options
for(var i=1; i<=12; ++i)
{
opt = new Option();
opt.text = i;
opt.value = i;
month.options[i-1] = opt;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<!--month options-->
You need to insert <form action=""> element here.
<SELECT name="month" id="month">
</SELECT>
<!--calling script-->
<SCRIPT>
PopulateMonths(); //calling populate for the above options
</SCRIPT>
</BODY>

</snippet>


I would validate your HTML markup code first of all, preferably with a
strict doctype decl. because that will trigger MSIE 6 into web standards
compliant rendering mode.

List of valid DTDs you can use in your document.
http://www.w3.org/QA/2002/04/valid-dtd-list.html

Like someone else in the thread said, you first need to embed that
<select> inside a <form>. <form> also requires an action attribute.

Your populate select function could be streamlined a bit and clarified also:

function PopulateMonths()
{
var objMonthSelect;
if(document.getElementById)
{
objMonthSelect = document.getElementById("month");
}
else if(document.all && !document.getElementById) // MSIE 4 only
{
objMonthSelect = month;
};
objMonthSelect.options.length = 0; //clear options
for(var i=0; i<12; i++)
{
opt = new Option();
opt.text = i;
opt.value = i;
objMonthSelect.options[i] = opt;
};
}

You should also always use differential (and preferably meaningful)
identifiers for name attribute and id attribute for several reasons:
code reviewing by others, better discrimination of how your code
accesses nodes, better understanding of your code inner logic. <select
name="month" id="month"> just confuses the way certain browser actually
accesses nodes when one does
month.[some attribute]

Since above 96% of all browsers in use out there support flawlessly
getElementById method, then there is no problem with replacing
month
by
document.getElementById("month")
with proper object support for that method

Finally, I recommend you always call functions like PopulateMonths() on
the onload event of the body element, not as the document is being
parsed and rendered for several reasons.

DU
Jul 23 '05 #5
Colin McKinnon <co**************@andthis.mms3.com> wrote in message
In IE, I could be able to directly refer the "id", but it isn't
possible in Firefox. Somewhere I read the solution is to refer the id
like document.getElementById("month") in Firefox. If I do so, the
script works well in Firefox, but IE throws error. (I have added the
code snippet below).
<snip> Odd, similar works OK for me across both IE and Firefox. Maybe IE is getting
upset because your assigning the widget to a variable with the same name as
an HTML Element in the same DOM scope? Try enclosing the select in
<form>...</form> or change the JS variable name.


Great! Your solutions work like a charm! Thanks for your time and help.

--
Email: rrjanbiah-at-Y!com
Jul 23 '05 #6
Mark Preston <us****@mpreston.demon.co.uk> wrote in message news:<ce*******************@news.demon.co.uk>...
<snip>

Many thanks to all the experts who answered in this thread. Your
solutions and answers are really helpful.
//month is id used with select
//month = document.getElementById("month"); //<-- for Firefox
month.options.length = 0; //clear options
for(var i=1; i<=12; ++i)

[snip]

I have no problem using code like yours in MSIE - perhaps you have an
older version of IE where the problem arises?


I'm using new versions of IE and Firefox. Colin McKinnon, Robert
and DU solutions are working great. Many thanks again.

--
Email: rrjanbiah-at-Y!com
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: tagdance | last post by:
Hello friends, I have a very interesting problem with my css files and firefox - I guess ! Listen: I have set up my new website www.tagdance.de For testing purpose I have mirrored this...
7
by: Merlin | last post by:
Hi there, I have a serious problem with opening a new window with the help of JavaScript. The problem only occures with Firefox. Once you click on the item which fires up the open function, the...
3
by: cwdjrxyz | last post by:
I suggest that everyone using a recent version of Firefox read http://forums.mozillazine.org/viewtopic.php?t=315656&sid=b1db62861b8da29535c43e9c5c527c3b at once. This new security problem was...
13
by: Giggle Girl | last post by:
Hi there, I am having a problem with the behavior of Firefox, where lefthand column content is not resized properly after it is "collapsed" and then "re-expanded". An online demo is available...
7
by: Xah Lee | last post by:
Look at this page http://xahlee.org/emacs/wrap-url.html Look at it in Firebox, look at it in Safari, in Opera, and look at it in Microsoft Internet Explorer. The only fucked up case, is...
1
by: tinnews | last post by:
I'm running a python script via the apache ExtFilterDefine directive, it works basically as expected *except* that when I change the script apache/firefox continue to run the old version of the...
3
by: willyWEB66 | last post by:
Hi everyone, I'm having problem with the sequence of execution for xml.onload. It works fine if your not passing parameters to onload event but my code needs to pass parameter to its function. I'm...
8
by: Atemporal | last post by:
When I click the link of this group, it shows the followings errors. Cannot find comp.lang.c%2B%2B There is no group named comp.lang.c%2B%2B. * The link you followed may be broken or...
15
by: Mike Driscoll | last post by:
Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. ...
6
by: Dennis | last post by:
I am in the process of converting some program output from HTML to XML/XSLT. I have an XSL stylesheet that inserts some javascript in the output that gets called further down to pop up a window)....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.