assigning values

Discussion in 'Javascript' started by Jes, Oct 30, 2007.

  1. Jes

    Jes Guest

    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
    Jes, Oct 30, 2007
    #1
    1. Advertising

  2. 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
    Thomas 'PointedEars' Lahn, Oct 30, 2007
    #2
    1. Advertising

  3. In comp.lang.javascript message <
    legroups.com>, Tue, 30 Oct 2007 15:08:51, Jes <>
    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.
    Dr J R Stockton, Oct 31, 2007
    #3
  4. Jes

    Jes Guest

    On Oct 31, 7:20 pm, Dr J R Stockton <> wrote:
    > In comp.lang.javascript message <
    > legroups.com>, Tue, 30 Oct 2007 15:08:51, Jes <>
    > 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. ? 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
    Jes, Nov 1, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnsy Joseph
    Replies:
    4
    Views:
    4,361
    Jim Lewis
    Sep 21, 2004
  2. Guest

    assigning values to form inputs

    Guest, Aug 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    520
  3. Tony Morris
    Replies:
    3
    Views:
    870
    Roedy Green
    Feb 4, 2006
  4. Moritz Beller
    Replies:
    2
    Views:
    280
    John Harrison
    Nov 7, 2004
  5. weston
    Replies:
    1
    Views:
    238
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page