Passing values

J

Jes

Hi

First, thanks to all for the help as I am new to JAVASCRIPT. I only
need to solve one last problem.

<td class="Input"><input id="BOOKINGDATE" name="BOOKINGDATE"
value="@BOOKINGDATE@">&nbsp;</td>

this is the field in table mysql
now I want to split in Day,Month,Year

<form name="form1" id="form1">
<td class="Input"><select name="BKDAY" id="BKDAY"> --- select option
from 1 to 31
<td class="Input"><select name="BKMONTH" id="BKMONTH"> --- select
option from 1 to 31
<td class="Input"><input name="BKYEAR" id="BKYEAR">
</form>

<script>
today = new Date();
document.form1.BKDAY.selectedIndex = today.getDate() - 1;
document.form1.BKMONTH.selectedIndex = today.getMonth();
document.form1.BKYEAR.value = today.getYear();
</script>

Value in BKYEAR is correct with today's year and the right options are
selected in BKDAY and BKMONTH.

However, I want to have the values that I have in the field
BOOKINGDATE and not of today.

I am trying
today = new Date(document.form1.BOOKINGDATE.value)
but it is not working.

Why please ?

Regards
Jesmond
 
L

Lee

Jes said:
I am trying
today = new Date(document.form1.BOOKINGDATE.value)
but it is not working.

Apparently, the value you're using isn't a valid date format,
but we can't be sure because you haven't shown us the value.


--
 
J

Jes

Jes said:


Apparently, the value you're using isn't a valid date format,
but we can't be sure because you haven't shown us the value.

--

Hi Lee,

When I put alert(today), I get

'1965-09-22'
 
T

Thomas 'PointedEars' Lahn

Please stop creating new threads for old topics.
First, thanks to all for the help as I am new to JAVASCRIPT. I only
need to solve one last problem.

<td class="Input"><input id="BOOKINGDATE" name="BOOKINGDATE"
value="@BOOKINGDATE@">&nbsp;</td>

this is the field in table mysql
now I want to split in Day,Month,Year

For the last time, do it server-side.
<form name="form1" id="form1">

This is not Valid HTML. http://validator.w3.org/
<td class="Input"><select name="BKDAY" id="BKDAY"> --- select option
from 1 to 31
<td class="Input"><select name="BKMONTH" id="BKMONTH"> --- select
option from 1 to 31
<td class="Input"><input name="BKYEAR" id="BKYEAR">
</form>

Let the server generate an

<option ... selected>...</option>

element where the date fits, and an

<option ...>...</option>

where it doesn't.

today = new Date();

var today = new Date();
document.form1.BKDAY.selectedIndex = today.getDate() - 1;

Still proprietary.

document.forms["form1"].elements["BKDAY"].selectedIndex = ...;
document.form1.BKMONTH.selectedIndex = today.getMonth();
document.form1.BKYEAR.value = today.getYear();

Same here.
</script>

Value in BKYEAR is correct with today's year and the right options are
selected in BKDAY and BKMONTH.

However, I want to have the values that I have in the field
BOOKINGDATE and not of today.

Therefore you should do it server-side in the first place.
I am trying
today = new Date(document.form1.BOOKINGDATE.value)

Should be

var today =
new Date(document.forms["form1"].elements["BOOKINGDATE"].value);

if that.

Why not?


PointedEars
 
T

Thomas 'PointedEars' Lahn

Jes said:
Jes said:
I am trying
today = new Date(document.form1.BOOKINGDATE.value)
but it is not working.
Apparently, the value you're using isn't a valid date format,
but we can't be sure because you haven't shown us the value.
[...]

[...] When I put alert(today), I get

'1965-09-22'

Before or after that statement? If before, the output of

window.alert(document.form1.BOOKINGDATE.value);

would be far more useful.

And you also haven't said which browser you are using, which version with
which operating system on which platform.


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
glegroups.com>, Wed, 31 Oct 2007 15:54:11, Jes

It is doing exactly what it should. If you want to be told in what
fashion your understanding is inadequate, then you should tell us the
EXACT content of that .value string and the resulting value of today.

When I put alert(today), I get

'1965-09-22'

That is a valid date format. It is the International standard (ISO
8601), logical, preferred, etc.

But Javascript was originated under Merkin influence, and hence will not
(generally; relevant behaviour is undefined in ISO/IEC 16262) accept
that form. However, it can accept that field order in a string (AFAIK,
in all browsers).

If you had used the newsgroup FAQ thoughtfully, you would have been led
to the information you needed (js-date3) ; see sig. Consider

var S = '2007-12-25 13:30'
var D = new Date(S.replace(/-/g, '/'))
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top