Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > assigning values

Reply
Thread Tools

assigning values

 
 
Jes
Guest
Posts: n/a
 
      10-30-2007
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

 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-30-2007
Jes wrote:
> 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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-31-2007
In comp.lang.javascript message <(E-Mail Removed)
legroups.com>, Tue, 30 Oct 2007 15:08:51, Jes <(E-Mail Removed)>
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.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript 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.
 
Reply With Quote
 
Jes
Guest
Posts: n/a
 
      11-01-2007
On Oct 31, 7:20 pm, Dr J R Stockton <(E-Mail Removed)> wrote:
> In comp.lang.javascript message <(E-Mail Removed)
> legroups.com>, Tue, 30 Oct 2007 15:08:51, Jes <(E-Mail Removed)>
> 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.
>
> --
> (c) John Stockton, Surrey, UK. ?(E-Mail Removed) Turnpike v6.05 IE 6
> news:comp.lang.javascript 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
if instance variable get initialize after assigning some values or after constructor then when does static variable get initialize Tony Morris Java 3 02-04-2006 08:39 AM
Failure while assigning values to a variable: Aborted Moritz Beller C++ 2 11-07-2004 07:18 PM
Assigning values to a multidimential array Johnsy Joseph VHDL 4 09-21-2004 01:29 PM
assigning values to form inputs ASP .Net 3 08-24-2004 12:16 PM



Advertisments