Click to See Complete Forum and Search --> : Form problem. Receive"null or not an object" error message


janvanheerden
12-16-2002, 09:21 PM
Hello everybody,

I am designing a web site where the clients fill in forms and submit orders.

I have 4 pages and 2 of them have forms.
In the forms I ask for personal details which I send to a database. Everything works fine up to that point.

The problems start when I want to generate a unique reference number that consists of a surname, date and time.

I inserted the following script in the head section:

<script language = "JavaScript">
var date1 = new Date()
var mont = date1.getMonth() + 1 // To display the correct month
</script>

I inserted the following script into the input tag of the submit button:

<input type="submit" value="Submit" name="B1" onClick = "document.Clients.RefNo.value = document.Clients.Surname.value + date1.getDate() + mont + date1.getHours() + date1.getMinutes()" >

Where:
Clients - name of form
RefNo - name of textbox
Surname - name of textbox

I have a one page web (the Try page) where I try out script before I use it in the main site. The above works perfectly in the Try page.

When I insert the code into the main page, I get the following error message:

'document.Clients.RefNo' is null or not an object.

I have tried various other syntaxes without success. The only difference between the Try and main pages, is that Try only has one page and I use an ordinary button there to test the script.

I would appreciate it if somebody could put me on the right track.

Thanks,

Jan van Heerden
janvanheerden@worldonline.co.za

khalidali63
12-16-2002, 09:45 PM
Hello,
below is the modified code and it does what you intend to do..

<script language = "JavaScript">
var date1 = new Date()
var mont = date1.getMonth() + 1 // To display the correct month
</script>
<form name="Clients">
Surname:<input type="Text" name="Surname"></input>
RefNo:<input type="Text" name="RefNo"></input>
<input type="submit" value="Submit" name="B1" onClick = "alert(document.Clients.RefNo.value = document.Clients.Surname.value + date1.getDate() + mont + date1.getHours() + date1.getMinutes())" >
</form>

Khalid

janvanheerden
12-17-2002, 11:13 AM
Khalid,

I tried your suggestion, but it does not work. I still get an
"Object expected" error message.

Do you have any other ideas?

Thanks,

Jan van Heerden

khalidali63
12-17-2002, 11:27 AM
Hello Jan,
You must have something else in the code that is creating problem,
Try this create a new empty html page
then copy all the code below,
save it and run it,I have tested it on NS6+ and IE5+

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<script language = "JavaScript">
var date1 = new Date()
var mont = date1.getMonth() + 1 // To display the correct month
</script>
<form name="Clients">
Surname:<input type="Text" name="Surname"></input>
RefNo:<input type="Text" name="RefNo"></input>
<input type="submit" value="Submit" name="B1" onClick = "alert(document.Clients.RefNo.value = document.Clients.Surname.value + date1.getDate() + mont + date1.getHours() + date1.getMinutes())" >
</form>

</body>
</html>

janvanheerden
12-19-2002, 12:08 PM
Hello Khalid,

I eventually found out what was wrong. (Sort of)

I am using FrontPage to design my web site. On two of the pages I have forms which I gave the names Clients and Subjects. I wrote the script using these names and kept getting 'null or not an object' error messages.

For some reason (which I have not figured out yet) FP changed the names of the forms to FrontPage_Form1 and FrontPage_Form2. I used the Clients and Subjects names in my script, therefor the error. I changed the names and it worked OK.

So we learn.

In any case, I appreciate your help very much. I have encountered another problem (so what's new!) which I am trying to sort out. Before you know it I will be knocking on your front door again.

Keep well,

Jan van Heerden

khalidali63
12-19-2002, 12:16 PM
Well honestly,I'd recomend not using any WYSIWYG utils,
its just like giving your control to some one else and expect that they would do what you are thinking.
But thats just me.

Cheers

email me if another problem rises

k_ali@shaw.ca

Khalid

janvanheerden
12-19-2002, 01:24 PM
Hello Khalid,

I was afraid you would say something like that.

My main concern at this stage is to get my website up and running which is proving more difficult than I thought.

I recently had a foot operation and I thought it would be better to learn something useful (like finding out how to design web pages) rather than sitting around feeling sorry for myself.

I am only starting to learn about HTML, DHTML, ASP, DOM, JavaScript and all that stuff. Quite a steep learning curve.

I understand that pros like you 'frown upon' amateurs like myself using wysiwyg programs. Pse bear with me.

Regards,

Jan van Heerden