473,320 Members | 1,957 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.

How to add <option> on Mac IE 5.0+

My code works under MS IE6,
but not work on Firefox and Mac IE5.1.2
Mac IE5.1.2 response: 'options' is not an object

function to check leap year
Source code:
--------------------------------------------------------------------
function setStartDayOpt() {
var year = document.getElementById('startYear');
var month = document.getElementById('StartMonth');
var day = document.getElementById('startDay');
var i, j, m, y, temp;

m = month.options[month.selectedIndex].value;
y = year.options[year.selectedIndex].value

if (year && month && day) {
if (m==4 || m==6 || m==9 || m==11) {
i=30;
} else {
i=31;
}
if (m==2) {
if (y/4 == parseInt(y/4)) {
i = 29;
} else {
i = 28;
}
}
if (day.options.length == j) {
return false;
} else {
day.options.length = 0
}
for (j=0; j<i; j++) {
temp = new Option(j+1, j+1);
alert(temp);
day.options[j] = temp;
temp = null;
}
}
}
------------------------------------------------------------------------------------------
Please advise, thanks.

Jun 12 '06 #1
5 1349
Cylix wrote:
My code works under MS IE6,
but not work on Firefox and Mac IE5.1.2
Mac IE5.1.2 response: 'options' is not an object

function to check leap year
Source code:
--------------------------------------------------------------------
function setStartDayOpt() {
var year = document.getElementById('startYear');

<snip>

If "startYear" is not assigned to the _ID_ attribute of the form
control (if it is the NAME of the control instead/only) then Windows IE
will retrieve a reference to the control using getElementById and most
other browsers will not (as they take the "Id" in getElementById as
meaning what it says).

Richard.

Jun 12 '06 #2
Cylix wrote:
My code works under MS IE6,
but not work on Firefox and Mac IE5.1.2
Mac IE5.1.2 response: 'options' is not an object

function to check leap year


It seems you are trying to put an appropriate number of days in a 'days'
option to match the year and month. Remember that browsers without
script should still be able to use your select elements.

There is a suggested script below, if scripting is not enabled it will
still work OK. Tested in IE 5.2, Safari and Firefox.

I've substituted a different 'daysInMonth' function, keep it if you like
(or not...). document.write is used to generate the initial days
options just for posting, use HTML in real life.
<html>
<head>
<title>date selector example</title>
<script type="text/javascript">

function daysInMonth(y, m)
{
m = +m + 1;
m = (m<10)? '0'+m : ''+m;
var x = new Date(y+'/'+m+'/'+'00');
return x.getDate();
}

function addDays()
{
var year = document.calendar.year;
var month = document.calendar.month;
var day = document.calendar.day;
var numDays = daysInMonth(year[year.selectedIndex].value,
month[month.selectedIndex].value);
day.options.length = 0;
for (var i=0; i<numDays; i++){
day.options[i] = new Option(i+1, i+1);
}
}

</script>
</head>

<body>
<form name="calendar" action="">
<select id="year" onchange="addDays()">
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
</select>
<select id="month" onchange="addDays()">
<option value="1">January
<option value="2">February
<option value="3">March
<option value="4">April
<option value="5">May
<option value="6">June
</select>
<select id="day">
<script type="text/javascript">
// Used just to cut down on code, use HTML in production
var t = '';
var i = 0;
while(i < 31){
t += '<option value="'+ ++i +'">'+i;
}
document.write(t);
</script>
</select>
</form>
</body>
</html>
--
Rob
Jun 12 '06 #3
You are so smart.
Actually, I still don't under start the behaviour.
After I change to the following in my script, my script also work fine:
var year = document.calendar.year;
var month = document.calendar.month;
var day = document.calendar.day;
RobG wrote:
Cylix wrote:
My code works under MS IE6,
but not work on Firefox and Mac IE5.1.2
Mac IE5.1.2 response: 'options' is not an object

function to check leap year


It seems you are trying to put an appropriate number of days in a 'days'
option to match the year and month. Remember that browsers without
script should still be able to use your select elements.

There is a suggested script below, if scripting is not enabled it will
still work OK. Tested in IE 5.2, Safari and Firefox.

I've substituted a different 'daysInMonth' function, keep it if you like
(or not...). document.write is used to generate the initial days
options just for posting, use HTML in real life.
<html>
<head>
<title>date selector example</title>
<script type="text/javascript">

function daysInMonth(y, m)
{
m = +m + 1;
m = (m<10)? '0'+m : ''+m;
var x = new Date(y+'/'+m+'/'+'00');
return x.getDate();
}

function addDays()
{
var year = document.calendar.year;
var month = document.calendar.month;
var day = document.calendar.day;
var numDays = daysInMonth(year[year.selectedIndex].value,
month[month.selectedIndex].value);
day.options.length = 0;
for (var i=0; i<numDays; i++){
day.options[i] = new Option(i+1, i+1);
}
}

</script>
</head>

<body>
<form name="calendar" action="">
<select id="year" onchange="addDays()">
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
</select>
<select id="month" onchange="addDays()">
<option value="1">January
<option value="2">February
<option value="3">March
<option value="4">April
<option value="5">May
<option value="6">June
</select>
<select id="day">
<script type="text/javascript">
// Used just to cut down on code, use HTML in production
var t = '';
var i = 0;
while(i < 31){
t += '<option value="'+ ++i +'">'+i;
}
document.write(t);
</script>
</select>
</form>
</body>
</html>
--
Rob


Jun 13 '06 #4
Cylix wrote:
You are so smart.
Please don't top post in this group. Reply below quoted text, and trim
what is no longer relevant.
Actually, I still don't under start the behaviour.
After I change to the following in my script, my script also work fine:
var year = document.calendar.year;
var month = document.calendar.month;
var day = document.calendar.day;


Probably for exactly the reason that Richard noted - your elements had
'name' attributes but not 'id' attributes - IE tends to treat them the
same, so when using getElementById it will return an element with a
matching name attribute value. Other browsers treat name and id as
different attributes (because they are) and won't match name values
using getElementById.

The formal version of the above is:

var year = document.forms['calendar'].elements['year'];
var month = document.forms['calendar'].elements['month'];
var day = document.forms['calendar'].elements['day'];

which uses the document's forms collection, not its getElementById
method.

It is generally advisable to use the forms collection wherever possible
as it works consistently in pretty much every browser since Navigator 2
& IE 3.
--
Rob

Jun 13 '06 #5
JRS: In article <448d48e9$0$7207$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Mon, 12 Jun 2006 20:58:39 remote, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.au> posted :

function daysInMonth(y, m)
{
m = +m + 1;
m = (m<10)? '0'+m : ''+m;
var x = new Date(y+'/'+m+'/'+'00');
return x.getDate();
}


Using new Date(Y, M, 0) seems simpler; and
new Date(Date.UTC(Y, M, 0)).getUTCDate() may be faster.

The OP's code is for the Julian calendar; ours is for the Gregorian.

The OP had :-
if (m==2) {
if (y/4 == parseInt(y/4)) {
i = 29;
} else {
i = 28;
}
}

but this is simpler :-
if (m==2) i = 28 + (y%4==0)

That way of using parseInt, I guess, comes from an old & bad book,
possibly via a low-grade lecturer.
However, I know little of Macs.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 13 '06 #6

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

Similar topics

2
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
1
by: frey | last post by:
i tried to create a dropdown menu and use the option as a control to change content inside another text area the code is like this: <select name="xxxx"><option onclick="changeunitprice(29.87)"...
4
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
7
by: Shrek | last post by:
I have a drop down on a web page and want to change the cursor from default to pointer, so my style definition has style ="cursor: pointer;" the drop down though fails to change from the...
4
by: pplers | last post by:
Here is config.php: <?php //The vars are all ok. $dbhost = 'localhost'; $dbname = 'forum'; $dbuser = 'toor'; $dbpass = ''; ?> Here is a part of functions.php: <? require "config.php"; //It...
14
by: The Natural Philosopher | last post by:
This is a nasty one and I can't see my way out of it. I have a bunch of select statements in a form, and each select statement has an onchange="do_something(this)" in it, and this works...
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.