R
R. Rajesh Jeba Anbiah
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>
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>