assigning values

J

Jes

Hi

I have a problem with assigning values in a form. I have a date field
in MySql and when I load the form , I would like to spilt it up in 3
fields ie day, month and year. I created 3 fields in the form ie.

<td class="Input"><input name="BKYEAR" size=8 id="BKYEAR">
<td class="Input"><select name="BKMONTH" size=8 id="BKMONTH">
<td class="Input"><select name="BKDAY" size=8 id="BKDAY">

On loading the form I would like to create a function that reads the
date field and spilt them to these fields so that each filed display
the values correctly from the date.

function readdate() {
var today = new Date();
today = document.getElementById("txtBookingsBOOKINGDATE").value;
alert(today)
BKDAY = today.getDate();
}

On the last line , I am getting an the following error:
'Object doesn't support this property or method'

Why ?

Thanks
Jesmond
 
T

Thomas 'PointedEars' Lahn

Jes said:
I have a problem with assigning values in a form. I have a date field
in MySql and when I load the form , I would like to spilt it up in 3
fields ie day, month and year. I created 3 fields in the form ie.
"ie"?

<td class="Input"><input name="BKYEAR" size=8 id="BKYEAR">
<td class="Input"><select name="BKMONTH" size=8 id="BKMONTH">
<td class="Input"><select name="BKDAY" size=8 id="BKDAY">

On loading the form I would like to create a function that reads the
date field and spilt them to these fields so that each filed display
the values correctly from the date.

That's really a very bad idea because it will work only with client-side
script support. You have MySQL available, so most certainly you have a
server-side application available, e.g. PHP. Let that generate the form
with the fields instead.
function readdate() {
var today = new Date();
today = document.getElementById("txtBookingsBOOKINGDATE").value;
alert(today)
window.alert(today);

BKDAY = today.getDate();
}

On the last line , I am getting an the following error:
'Object doesn't support this property or method'

Why ?

Fantasy syntax; a String object is not a Date object, and your DOM approach
is IE-proprietary. RTFM.

http://jibbering.com/faq/


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
legroups.com>, Tue, 30 Oct 2007 15:08:51, Jes <[email protected]>
posted:

There is no type information associated with a javascript identifier
itself, but the type information is with the content of the variable.

function readdate() {
var today = new Date();
That sets today to a Date Object representing the current instant.
today = document.getElementById("txtBookingsBOOKINGDATE").value;
That sets today to a String given by a control, abandoning the Date
Object. You may think it looks like a Date; Javascript does not (yet).
alert(today)
That should show the String.
BKDAY = today.getDate();
A String has no getDate property.
}

On the last line , I am getting an the following error:
'Object doesn't support this property or method'
That is proper.

You could use
var St = document.getElementById("txtBookingsBOOKINGDATE").value
var today = new Date(St)
but I don't guarantee that the second statement will like the
unspecified format of St.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
J

Jes

In comp.lang.javascript message <[email protected]
legroups.com>, Tue, 30 Oct 2007 15:08:51, Jes <[email protected]>
posted:

There is no type information associated with a javascript identifier
itself, but the type information is with the content of the variable.


That sets today to a Date Object representing the current instant.


That sets today to a String given by a control, abandoning the Date
Object. You may think it looks like a Date; Javascript does not (yet).


That should show the String.


A String has no getDate property.



That is proper.

You could use
var St = document.getElementById("txtBookingsBOOKINGDATE").value
var today = new Date(St)
but I don't guarantee that the second statement will like the
unspecified format of St.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. [email protected] Turnpike v6.05 IE 6
FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top