January 28th, 2003, 01:55 AM
|
#1 (permalink)
| | Member
Join Date: Aug 2002 Location: Downunder
Posts: 432
|
the following javascript code works in IE, but isn't working in Netscape...please help...
i'm trying to print 3 dropdown boxes ... month, date, year... as part of a form...
'theMonths' and 'theYears' arrays are defined earlier
please mention if u need further info...
<script language="JavaScript" type="text/javascript">
<!--
var content = "<tr><td ALIGN='left' VALIGN='MIDDLE' width=136><div align='left'><p>Date last modified:</td><td ALIGN='left' width=406 valign='middle'><div align='left'><p><select NAME=month onChange=validateMonth(this)><option selected>Month"
// prints 'theMonths' array
for(i = 0; i <= 11; i++) {
content+= "<option>"+theMonths[i]
}
content+="</select>"
content+=" <select NAME=date onChange=validateDate(this)><option selected>Date"
// prints 31 days
for(i = 1; i <= 31; i++) {
content+= "<option>"+i
}
content+="</select>"
content+=" <select NAME=year onChange=validateYear(this)><option selected>Year"
// prints 'theYears' array
for(i = 0; i <= theYears.length; i++) {
content+= "<option>"+theYears[i]
}
content+="</select></td></tr>"
document.write(content)
-->
</script>
getting very frustrated!!!! below is how it appears in IE and netscape |
| |
January 28th, 2003, 02:04 AM
|
#2 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,549
|
View the source does it print correctly?
Also netscape has a javascript validator. Is it reporting errors? If so what?
Jkrohn
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
|
| |
January 28th, 2003, 02:13 AM
|
#3 (permalink)
| | Member
Join Date: Aug 2002 Location: Downunder
Posts: 432
|
looks like the 'theYears' array is not printing for some reason
this is how i create the 'theYears' array...
var startYear = 1990 // starting value of 'year' field
var today = new Date() // today's date
// size of 'year' array is the number of years between
// 'startYear' and current year
yearArraySize = today.getYear() - startYear
// create basic array
theYears = new MakeYearsArray(yearArraySize)
// load array with years from start to current
function MakeYearsArray(n) {
j=0
for(i = startYear; i <= today.getYear(); i++) {
this[j] = i
j++
}
this.length = n
return this
}
and printing the array as pasted in previous post is done as follows:
// prints 'theYears' array
for(i = 0; i <= theYears.length; i++) {
content+= "<option>"+theYears[i]
}
jkrohn: how to access 'javascript validator' mate?? do u mean the 'java console'? dont think so... this is communicator 4.08, cant find any javascript validator...open my eyes |
| |
January 28th, 2003, 02:19 AM
|
#4 (permalink)
| | Member
Join Date: Aug 2002 Location: Downunder
Posts: 432
|
found the javascript validator i suppose
have to type 'javascript:' in the location bar...
doesn't like the way i'm enclosing my code
e.g. say i have the following...
<!--
var content .....
-->
the validator reports...
JavaScript Error: file:/P|/Site/upload_file.html, line 234:
syntax error.
-->
..^
-------
got rid of the <!-- -->, still no difference
Last edited by nishark : January 28th, 2003 at 02:22 AM.
|
| |
January 28th, 2003, 07:28 PM
|
#5 (permalink)
| | Member
Join Date: Aug 2002 Location: Downunder
Posts: 432
|
ok, i did some debugging after taking a time out. the problem still persists. please help.
following are the code snippets that i think is the root of it all
1 var startYear = 1990
2 var today = new Date()
3 var yearArraySize = (today.getYear() - startYear) + 1
4 var theYears = new Array(yearArraySize)
5
6 function MakeYearsArray(n) {
7 var i = startYear
8 for(j = 0; j <= n; j++) {
9 theYears[j] = i
10 i++
11 }
12 }
13
14 MakeYearsArray(yearArraySize)
15
16 content+=" <select NAME=year><option selected>Year"
17
18 for(i = 0; i <= yearArraySize; i++) {
19 content+="<option>"+theYears[i]
20 }
21
22 content+="</select>"
23 document.write(content)
IE 5.5 prints a dropdown 'select box' with entries from 1990 - 2003
Netscape(Communicator 4.08) doesnt. Following is the netscape HTML output
<SELECT NAME=year><OPTION selected>Year</SELECT>
after applying the debugging tactics that i'm aware of, it looks to me that for some reason netscape doesn't like the use of a loop to initialise array elements.
to be precise, it doesnt like the use of variables in lines 8 (n) and 18 (yearArraySize)
if i replace the variables 'n' and 'yearArraySize' in lines 8 and 18 with integers, the loops work fine.
javascript validator does not produce any errors.
anyone got any ideas as to why netscape doesnt like my code? |
| |
January 28th, 2003, 08:29 PM
|
#6 (permalink)
| | Member
Join Date: Aug 2002 Location: Downunder
Posts: 432
|
alright, i solved it, persistence and googling paid off...
it was line 3 of the code snippet. netscape interprets the getYear() method differently compared to IE. getFullYear() serves the purpose http://www.webreference.com/js/tips/000108.html
phew!! (wipes sweat of his forehead) |
| |
January 28th, 2003, 10:01 PM
|
#7 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: Alberta, Canada
Posts: 563
|
doh! I'm too slow!!
cheers! |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |