home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2779
Discussions: 188,384, Posts: 2,243,508, Members: 232,615
Old January 28th, 2003, 01:55 AM   Digg it!   #1 (permalink)
Member
 
nishark's Avatar
 
Join Date: Aug 2002
Location: Downunder
Posts: 432
cross browser javascript

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
Attached Thumbnails
cross-browser-javascript-2screens.jpg  

nishark is offline   Reply With Quote
Old January 28th, 2003, 02:04 AM     #2 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,549
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
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.

jkrohn is offline   Reply With Quote
Old January 28th, 2003, 02:13 AM     #3 (permalink)
Member
 
nishark's Avatar
 
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

nishark is offline   Reply With Quote
Old January 28th, 2003, 02:19 AM     #4 (permalink)
Member
 
nishark's Avatar
 
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.
nishark is offline   Reply With Quote
Old January 28th, 2003, 07:28 PM     #5 (permalink)
Member
 
nishark's Avatar
 
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?
nishark is offline   Reply With Quote
Old January 28th, 2003, 08:29 PM     #6 (permalink)
Member
 
nishark's Avatar
 
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)
nishark is offline   Reply With Quote
Old 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!
^hyd^ is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2896)
CPU wont boot (6)
3-days in and no threads about Gaza (160)
The United States Debt (20)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Recent Discussions
CPU wont boot (6)
GLaDOS is up. (3)
HP notebook reinstall Vista NO .. (5)
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
Creative T-3000 Subwoofer (3)
ACPI controller halt on boot (2)
Worth the upgrade?? (15)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 10:32 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28