473,326 Members | 2,173 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,326 software developers and data experts.

Javascript Form Help

2
I am VERY new at javascript and I cannot seem to figure out why I keep getting the following error message when I try to run this code:

Error
"document.myform is null or not an object"

I just want to pass the name epoch and the value "date_val" that is returned from the function get_date()

Any help would be greatly appreciated!

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Password Changer</title>

</head>

<body>

<FORM NAME="myform">
<p>
<INPUT TYPE="Submit" Action="/cgi-bin/test_pass.cgi" Method="POST" NAME="epoch" VALUE="date_val" onClick="get_date()">

</FORM></p>

<script language="JavaScript">


<!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function daysElapsed(date1,date2) {
var difference =
Date.UTC(y2k(date2.getYear()),date2.getMonth(),dat e2.getDate(),0,0,0)
- Date.UTC(y2k(date1.getYear()),date1.getMonth(),dat e1.getDate(),0,0,0);
return difference/1000/60/60/24;

}

function get_date() {
var now = new Date();
var date_val = daysElapsed(new Date(1970,1,1),new Date(now.getYear(), now.getMonth() +1, now.getDate() +1));
document.write(date_val);
document.myform.action='/cgi-bin/test_pass.cgi';
document.myform.submit();
}
//-->
</script>
</body>
</html>
Jun 5 '07 #1
4 1469
pbmods
5,821 Expert 4TB
Heya, init0. Welcome to TSDN!

Try using document.forms.myForm instead.

Or give your form an id:

Expand|Select|Wrap|Line Numbers
  1. <form id="myForm">
  2.  
Then access it using
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('myForm')
.
Jun 5 '07 #2
init0
2
Heya, init0. Welcome to TSDN!

Try using document.forms.myForm instead.

Or give your form an id:

Expand|Select|Wrap|Line Numbers
  1. <form id="myForm">
  2.  
Then access it using
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('myForm')
.
Thanks for your input, I tried both and I still get the same error message?
Jun 6 '07 #3
Logician
210 100+
function get_date() {
var now = new Date();
var date_val = daysElapsed(new Date(1970,1,1),new Date(now.getYear(), now.getMonth() +1, now.getDate() +1));
document.write(date_val);
document.myform.action='/cgi-bin/test_pass.cgi';
document.myform.submit();
}
If you call document.write after the page has loaded; the current content of the page is lost.
Jun 6 '07 #4
pbmods
5,821 Expert 4TB
If you call document.write after the page has loaded; the current content of the page is lost.
Ooh! Good eye! I completely missed that.

Instead of using document.write, try creating a div with an ID and dynamically altering its #text child:

Expand|Select|Wrap|Line Numbers
  1. <div id="scriptOutput">&nbsp;</div>
  2.  
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('scriptOutput').firstChild.nodeValue = date_val;
  2.  
For an explanation of why this works, check out this article.
Jun 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.