DTP


 
Lively discussions on the graphic arts and publishing — in print or on the web


Go Back   Desktop Publishing Forum > General Discussions > Web Site Building & Maintenance

Reply
 
Thread Tools Display Modes
Old 09-01-2005, 08:05 AM   #1
ilox
Member
 
ilox's Avatar
 
Join Date: Aug 2005
Location: Adelaide, South Australia
Posts: 104
Default Help with JavaScript coding

I'm in the middle of a web design course and the current assignment is about using JavaScript to verify entries on an order form. I have pretty well all the work done but am having trouble on a couple of areas.
First one is this script given to us in the tutorial to demonstrate a simple script.
Code:
<script language="JavaScript" >
 currentDate=new Date(); 
with (currentDate){document.write( getDate() +"/" + getMonth()
 + "/" + getYear())}
</script>
I need to provide a page which has this date component in it but the darn thing is giving the wrong month! When I run it I get the month as 8 instead of 9. My computer is running at the correct date (I just double checked) so why is this thing showing August?

Second problem is a page that brings up a Help page when a button is pushed. This runs under a set of frames (blech!) so the code for this is
Code:
 function openHelp() {
    parent.frames[1].location.href="joeshelp.html";
   }

 <input type="button" value="Click to open the Help page"
  onclick="openHelp(event);">
What I was hoping to do was set it up so the help page could be opened whether the order form was in the frames or running on its own.

Anybody able to give me some clues or point me in the right direction about this stuff?

   
__________________
Cheers, Ian
ilox is offline   Reply With Quote
Old 09-01-2005, 08:39 AM   #2
ktinkel
Founding Sysop
 
ktinkel's Avatar
 
Join Date: Oct 2004
Location: In Connecticut, on the Housatonic River near its mouth at Long Island Sound.
Posts: 11,189
Default

Quote:
Originally Posted by ilox
… I need to provide a page which has this date component in it but the darn thing [JavaScript] is giving the wrong month! When I run it I get the month as 8 instead of 9.
JavaScript begins numbering at 0, so January and Sunday are 0, and the numbers go on from there.

(I am astounded that I am able to answer any JavaScript question — and you have now exhausted my lore of arcane JS-iana!)

BTW, I learned it from a good book: JavaScript for the World Wide Web (4th edition), by Tom Negrino and Dori Smith (Peachpit). I’m sure I would know more if I just applied myself!

   
__________________
[SIZE=2][COLOR=LemonChiffon]::[/COLOR][/SIZE]
[SIGPIC][/SIGPIC]
ktinkel is offline   Reply With Quote
Old 09-01-2005, 09:03 AM   #3
don Arnoldy
Curmudgeon
 
don Arnoldy's Avatar
 
Join Date: Oct 2004
Posts: 491
Default

Quote:
Originally Posted by ilox
the code for this is
Code:
 function openHelp() {
    parent.frames[1].location.href="joeshelp.html";
   }

 <input type="button" value="Click to open the Help page"
  onclick="openHelp(event);">
What I was hoping to do was set it up so the help page could be opened whether the order form was in the frames or running on its own.
You have to test to see if the page is in a frame or the the main window...

Code:
function openHelp() {
	if(self.location != top.location){
		parent.frames[1].location.href="joeshelp.html"
	}else{
		helpWindow = window.open("joeshelp.html", "helpwin", "toolbar=no,location=no,scrollbars=yes,width=400,height=600")
		helpWindow.focus()
	}
}

<input type="button" value="Click to open the Help page"
onclick="openHelp(event);">

   
__________________
--don
don Arnoldy is offline   Reply With Quote
Old 09-02-2005, 12:55 AM   #4
ilox
Member
 
ilox's Avatar
 
Join Date: Aug 2005
Location: Adelaide, South Australia
Posts: 104
Default

Wow! Many thanks for that. I knew there had to be a way but never thought of using an IF-ELSE. You can see I'm not a programmer though I did 2 years of it at Uni <sigh>

   
__________________
Cheers, Ian
ilox is offline   Reply With Quote
Old 09-03-2005, 05:22 AM   #5
ilox
Member
 
ilox's Avatar
 
Join Date: Aug 2005
Location: Adelaide, South Australia
Posts: 104
Default

Don, and any other readers, higher in this thread you will see I have provided the URLS for the Assignment site I am working on.

I have just spotted that the Submit button both sends the data off to be validated but also sends the email off for the order. Any ideas on how to block the sending of the email till the order is validated as complete and correct?

   
__________________
Cheers, Ian
ilox is offline   Reply With Quote
Old 09-03-2005, 03:07 PM   #6
donmcc
Member
 
Join Date: Feb 2005
Location: Sarnia, Canada
Posts: 1,122
Default

Can you repeat the URL? I can't find it.

Don McCahill
donmcc is offline   Reply With Quote
Old 09-07-2005, 12:50 AM   #7
ilox
Member
 
ilox's Avatar
 
Join Date: Aug 2005
Location: Adelaide, South Australia
Posts: 104
Default You'll find them here

Hi Don,
The frame based site is here:
http://www.tvicomputing.com/studentw...4w3/index.html

The non-frames view is here
http://www.tvicomputing.com/studentwebs/group1/student4/4w3/home4.html

Hope this helps, sorry for the confusion with the links.

   
__________________
Cheers, Ian

Last edited by ilox; 09-07-2005 at 12:52 AM. Reason: correction to URL
ilox is offline   Reply With Quote
Old 09-01-2005, 11:23 AM   #8
donmcc
Member
 
Join Date: Feb 2005
Location: Sarnia, Canada
Posts: 1,122
Default

The first one is easy. Most, but not all, the date functions in Javascript start with 0. So the month 0 is January and 11 is December.

Not sure about the second ... I have done little with frames for the past nine years or so, and nothing at all with them and JS.

Don
donmcc is offline   Reply With Quote
Old 09-02-2005, 12:36 AM   #9
ilox
Member
 
ilox's Avatar
 
Join Date: Aug 2005
Location: Adelaide, South Australia
Posts: 104
Default

Arrghh!! Somewhere I had read that and promptly forgot about it. Darn. Ok, so I need to add 1 to the values to get the right date.

Thanks for the heads up, I was starting to wonder about my sanity because the coding looked fine, and it was coding given to us in the tutorial <sigh>

much later ... he wrote ...
Code:
 currentDate=new Date(); with (currentDate){document.write( getDate()+1 +"/" + getMonth()+1 + "/" + getYear())}
... and what he got back was "Hello. Today is 3/81/2005. " AAARRRRGGGHHHH!!!!!!
BTW, for those who are hemispherically challenged - as I write this it is 1828 on 2 September.

Obviously that hack ain't gonna work!

much, much later .. I found out how I needed to do the addition
Code:
 currentDate=new Date(); 
with (currentDate){document.write( getDate() +"/" + [getMonth()+1]
   + "/" + getYear())}
and the result is...."Hello. Today is 2/9/2005"

So the next question is, are we having fun yet?

   
__________________
Cheers, Ian

Last edited by ilox; 09-02-2005 at 01:25 AM. Reason: adding code snippets
ilox is offline   Reply With Quote
Old 09-02-2005, 07:01 AM   #10
jgr
Member
 
Join Date: Dec 2004
Posts: 276
Default

Ian, try this site for date formats in javascript.

   
__________________
-- jgr
jgr is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox 1.5 JavaScript Console Kelvyn Web Site Building & Maintenance 0 12-13-2005 11:01 AM


All times are GMT -8. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Contents copyright 2004–2014 Desktop Publishing Forum and its members.