By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

What the he** am I missing here?

P: n/a
function SetDefaultDate() {
d = new Date();
return d;
}
........
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>
I just want to default the html control to todays date.

Why is this all so painful......maybe time for a career change :(
Jul 20 '05 #1
Share this Question
Share on Google+
28 Replies


P: n/a
@SM


Brent Eamer a ecrit :

function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
may be ... ?

value="<SCRIPT>document.write(SetDefaultDate())</SCRIPT>">
</TD>
</TR>

Jul 20 '05 #2

P: n/a
Brent Eamer wrote on 18 Dec 2003 at Thu, 18 Dec 2003 13:11:36 GMT:
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1"
maxlength="50" value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>


I was going to say: "That SCRIPT block is being interpreted as it's
supposed to be in that context: a CDATA (string) value." But when I
checked the HTML standard (to check that value attributes contain
CDATA), I realised that SELECT elements don't have value attributes;
the selected OPTION elements are the values for the SELECT. SELECT
elements don't have a maxlength attribute, either. Basically, even
if the script part of your HTML syntax was correct, which it isn't,
the above still wouldn't work.

Without knowing exactly what you were trying to acheive, I can't
give a definitive answer, but I can point you in the right
direction.

As I already said, what you are expecting from that HTML is *never*
going to happen. It's like specifying an IMG element as the value of
a BUTTON and expecting it to render the image:

<BUTTON value="<IMG src='someImage.gif'>"></BUTTON> [1]

There are two methods of doing what you hope to acheive:

1) Write the entire element using document.write(), concatenating
the date into a fixed string, or;
2) Assign the value to the element at some point after creating it
(when the onload event is fired, for example).

I'll assume below that in your HTML you wanted a drop-down box that
displayed, as it's initial option, the current local date only (not
time).

An example for the first method:

<SELECT name="batchStartDate" size="1">
<SCRIPT type="text/javascript">
// Notice that you forgot to specify the script type in your
// example.

var now = new Date();

document.write(
'<OPTION selected>' + now.getFullYear() + '-'
+ now.getMonth() + '-' + now.getDate() + '<\/OPTION>' );

// Produces the HTML: <OPTION selected>YYYY-M-d</OPTION>
//
// where YYYY is a four letter year
// M is the month (no leading zero)
// d is the day (no leading zero)
</SCRIPT>
</SELECT>
An example for the second method:

<HEAD>
<!-- Set the default script language
for the onload event below -->
<META http-equiv="Content-Script-Type"
content="text/javascript">

<SCRIPT type="text/javascript">
function insertCurrentDate() {
var now = new Date();
var value = now.getFullYear() + '-' + now.getMonth() + '-'
+ now.getDate();
var initial = null;

// Find the OPTION element and replace it's display text and
// value to the current date
if (document.getElementById) {
var initial = document.getElementById('initial');
} else if (document.all) {
var initial = document.all['initial'];
}
if (initial) {
initial.text = value;
initial.value = value;
}
}
</SCRIPT>
...
</HEAD>

<BODY onload="insertCurrentDate()">
...
<SELECT name="batchStartDate" size="1">
<OPTION id="initial" selected>Today</OPTION>
...
</SELECT>

I *seriously* recommend that you refresh your knowledge of HTML and
JavaScript.

Mike
[1] The correct syntax is, of course:

<BUTTON><IMG src="someImage.gif"></BUTTON>

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #3

P: n/a
In article <cI********************@ursa-nb00s0.nbnet.nb.ca>,
be****@islandtelecom.com enlightened us with...
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>
I just want to default the html control to todays date.

Why is this all so painful......maybe time for a career change :(


Because you're trying to set a value to a select element when select
elements have options and selectedIndex, not values. You're also giving
it a maxlength when that is not a property of select elements. Select
elements have options. Options have values.
Choose an option with your script (you'll either need a loop or you'll
need to know the option index to set it), then call the script in the
onLoad of the body. Note that this will muck things up if the user
presses the back button after leaving the page, as the date will be
reset instead of holding on as the user expects. To help this, I check
for a value before resetting it in my stuff.
If this were a text element, you should still set in the script by using
document.formname.elementname.value=d;
not try to call a script like you did above inside the value quotes.
That works fine with server-side <%= val %> type statements, but I've
never seen it used client-side with a script block.

--
--
~kaeli~
Is it possible to be totally partial?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4

P: n/a
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:cI********************@ursa-nb00s0.nbnet.nb.ca...
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>
I just want to default the html control to todays date.

Why is this all so painful......maybe time for a career change :(


1) size="1" does nothing useful

2) maxlength="50" does nothing

3) SELECT does not support "value="

4) You cannot assign a form value with JavScript in that manner.

5) Are you sure you want a SELECT?

Perhpas you want; (watch for word-wrap):

<script language="javascript" type="text/javascript">
<!--
var html = "<input type='text' name='BatchStartDate' size='10'
maxlength='10' value='";
var when = new Date();
html += when.getMonth()+1 + "/";
html += when.getDate() + "/";
html += when.getFullYear() + "'>";
document.write(html);
// -->
</script>
Note that the month and day will have leading zeroes suppressed; thus New
Year's Day will be shown as "1/1/2004".
Jul 20 '05 #5

P: n/a
Sorry guys, you are right, I don't want a select, cut and paste error. I
wanted the following:

function SetDefaultDate() {
rightnow = new Date("Month dd, yyyy");
return rightnow;
}

<TD align=left> <input type="text" name="batchStartDate" size="20"
maxlength="50" value="SetDefaultDate()">
However it still does not work, sorry for the confusion

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:trjEb.143715$_M.713535@attbi_s54...
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:cI********************@ursa-nb00s0.nbnet.nb.ca...
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>
I just want to default the html control to todays date.

Why is this all so painful......maybe time for a career change :(


1) size="1" does nothing useful

2) maxlength="50" does nothing

3) SELECT does not support "value="

4) You cannot assign a form value with JavScript in that manner.

5) Are you sure you want a SELECT?

Perhpas you want; (watch for word-wrap):

<script language="javascript" type="text/javascript">
<!--
var html = "<input type='text' name='BatchStartDate' size='10'
maxlength='10' value='";
var when = new Date();
html += when.getMonth()+1 + "/";
html += when.getDate() + "/";
html += when.getFullYear() + "'>";
document.write(html);
// -->
</script>
Note that the month and day will have leading zeroes suppressed; thus New
Year's Day will be shown as "1/1/2004".

Jul 20 '05 #6

P: n/a
Nope :)
"@SM" <st**************@wanadoo.fr> wrote in message
news:3F***************@wanadoo.fr...


Brent Eamer a ecrit :

function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">


may be ... ?

value="<SCRIPT>document.write(SetDefaultDate())</SCRIPT>">
</TD>
</TR>

Jul 20 '05 #7

P: n/a
Sorry to be picky but...

"now.getMonth()" returns 0 to 11 (not 1 to 12).

You example will display the previous month.
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:Xn*******************************@193.38.113. 46...
Brent Eamer wrote on 18 Dec 2003 at Thu, 18 Dec 2003 13:11:36 GMT:
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1"
maxlength="50" value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>


I was going to say: "That SCRIPT block is being interpreted as it's
supposed to be in that context: a CDATA (string) value." But when I
checked the HTML standard (to check that value attributes contain
CDATA), I realised that SELECT elements don't have value attributes;
the selected OPTION elements are the values for the SELECT. SELECT
elements don't have a maxlength attribute, either. Basically, even
if the script part of your HTML syntax was correct, which it isn't,
the above still wouldn't work.

Without knowing exactly what you were trying to acheive, I can't
give a definitive answer, but I can point you in the right
direction.

As I already said, what you are expecting from that HTML is *never*
going to happen. It's like specifying an IMG element as the value of
a BUTTON and expecting it to render the image:

<BUTTON value="<IMG src='someImage.gif'>"></BUTTON> [1]

There are two methods of doing what you hope to acheive:

1) Write the entire element using document.write(), concatenating
the date into a fixed string, or;
2) Assign the value to the element at some point after creating it
(when the onload event is fired, for example).

I'll assume below that in your HTML you wanted a drop-down box that
displayed, as it's initial option, the current local date only (not
time).

An example for the first method:

<SELECT name="batchStartDate" size="1">
<SCRIPT type="text/javascript">
// Notice that you forgot to specify the script type in your
// example.

var now = new Date();

document.write(
'<OPTION selected>' + now.getFullYear() + '-'
+ now.getMonth() + '-' + now.getDate() + '<\/OPTION>' );

// Produces the HTML: <OPTION selected>YYYY-M-d</OPTION>
//
// where YYYY is a four letter year
// M is the month (no leading zero)
// d is the day (no leading zero)
</SCRIPT>
</SELECT>
An example for the second method:

<HEAD>
<!-- Set the default script language
for the onload event below -->
<META http-equiv="Content-Script-Type"
content="text/javascript">

<SCRIPT type="text/javascript">
function insertCurrentDate() {
var now = new Date();
var value = now.getFullYear() + '-' + now.getMonth() + '-'
+ now.getDate();
var initial = null;

// Find the OPTION element and replace it's display text and
// value to the current date
if (document.getElementById) {
var initial = document.getElementById('initial');
} else if (document.all) {
var initial = document.all['initial'];
}
if (initial) {
initial.text = value;
initial.value = value;
}
}
</SCRIPT>
...
</HEAD>

<BODY onload="insertCurrentDate()">
...
<SELECT name="batchStartDate" size="1">
<OPTION id="initial" selected>Today</OPTION>
...
</SELECT>

I *seriously* recommend that you refresh your knowledge of HTML and
JavaScript.

Mike
[1] The correct syntax is, of course:

<BUTTON><IMG src="someImage.gif"></BUTTON>

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")

Jul 20 '05 #8

P: n/a
Refresh?
I'm fairly new to this stuff :)

I'm an old Oracle PL/SQL programmer, and boy some of this stuff can really
trip you up. Trying to upgrade my skills during my unemployment

Thanks

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:Xn*******************************@193.38.113. 46...
Brent Eamer wrote on 18 Dec 2003 at Thu, 18 Dec 2003 13:11:36 GMT:
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1"
maxlength="50" value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>


I was going to say: "That SCRIPT block is being interpreted as it's
supposed to be in that context: a CDATA (string) value." But when I
checked the HTML standard (to check that value attributes contain
CDATA), I realised that SELECT elements don't have value attributes;
the selected OPTION elements are the values for the SELECT. SELECT
elements don't have a maxlength attribute, either. Basically, even
if the script part of your HTML syntax was correct, which it isn't,
the above still wouldn't work.

Without knowing exactly what you were trying to acheive, I can't
give a definitive answer, but I can point you in the right
direction.

As I already said, what you are expecting from that HTML is *never*
going to happen. It's like specifying an IMG element as the value of
a BUTTON and expecting it to render the image:

<BUTTON value="<IMG src='someImage.gif'>"></BUTTON> [1]

There are two methods of doing what you hope to acheive:

1) Write the entire element using document.write(), concatenating
the date into a fixed string, or;
2) Assign the value to the element at some point after creating it
(when the onload event is fired, for example).

I'll assume below that in your HTML you wanted a drop-down box that
displayed, as it's initial option, the current local date only (not
time).

An example for the first method:

<SELECT name="batchStartDate" size="1">
<SCRIPT type="text/javascript">
// Notice that you forgot to specify the script type in your
// example.

var now = new Date();

document.write(
'<OPTION selected>' + now.getFullYear() + '-'
+ now.getMonth() + '-' + now.getDate() + '<\/OPTION>' );

// Produces the HTML: <OPTION selected>YYYY-M-d</OPTION>
//
// where YYYY is a four letter year
// M is the month (no leading zero)
// d is the day (no leading zero)
</SCRIPT>
</SELECT>
An example for the second method:

<HEAD>
<!-- Set the default script language
for the onload event below -->
<META http-equiv="Content-Script-Type"
content="text/javascript">

<SCRIPT type="text/javascript">
function insertCurrentDate() {
var now = new Date();
var value = now.getFullYear() + '-' + now.getMonth() + '-'
+ now.getDate();
var initial = null;

// Find the OPTION element and replace it's display text and
// value to the current date
if (document.getElementById) {
var initial = document.getElementById('initial');
} else if (document.all) {
var initial = document.all['initial'];
}
if (initial) {
initial.text = value;
initial.value = value;
}
}
</SCRIPT>
...
</HEAD>

<BODY onload="insertCurrentDate()">
...
<SELECT name="batchStartDate" size="1">
<OPTION id="initial" selected>Today</OPTION>
...
</SELECT>

I *seriously* recommend that you refresh your knowledge of HTML and
JavaScript.

Mike
[1] The correct syntax is, of course:

<BUTTON><IMG src="someImage.gif"></BUTTON>

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")

Jul 20 '05 #9

P: n/a
Did you see the code at the bottom of my response?

"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:pz********************@ursa-nb00s0.nbnet.nb.ca...
Sorry guys, you are right, I don't want a select, cut and paste error. I
wanted the following:

function SetDefaultDate() {
rightnow = new Date("Month dd, yyyy");
return rightnow;
}

<TD align=left> <input type="text" name="batchStartDate" size="20"
maxlength="50" value="SetDefaultDate()">
However it still does not work, sorry for the confusion

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:trjEb.143715$_M.713535@attbi_s54...
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:cI********************@ursa-nb00s0.nbnet.nb.ca...
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>
I just want to default the html control to todays date.

Why is this all so painful......maybe time for a career change :(


1) size="1" does nothing useful

2) maxlength="50" does nothing

3) SELECT does not support "value="

4) You cannot assign a form value with JavScript in that manner.

5) Are you sure you want a SELECT?

Perhpas you want; (watch for word-wrap):

<script language="javascript" type="text/javascript">
<!--
var html = "<input type='text' name='BatchStartDate' size='10'
maxlength='10' value='";
var when = new Date();
html += when.getMonth()+1 + "/";
html += when.getDate() + "/";
html += when.getFullYear() + "'>";
document.write(html);
// -->
</script>
Note that the month and day will have leading zeroes suppressed; thus New Year's Day will be shown as "1/1/2004".


Jul 20 '05 #10

P: n/a
Yes

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:iVjEb.423032$ao4.1356533@attbi_s51...
Did you see the code at the bottom of my response?

"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:pz********************@ursa-nb00s0.nbnet.nb.ca...
Sorry guys, you are right, I don't want a select, cut and paste error. I
wanted the following:

function SetDefaultDate() {
rightnow = new Date("Month dd, yyyy");
return rightnow;
}

<TD align=left> <input type="text" name="batchStartDate" size="20"
maxlength="50" value="SetDefaultDate()">
However it still does not work, sorry for the confusion

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:trjEb.143715$_M.713535@attbi_s54...
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:cI********************@ursa-nb00s0.nbnet.nb.ca...
> function SetDefaultDate() {
> d = new Date();
> return d;
> }
> .......
> <TD align=left> Start Date: </TD>
> <TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50" > value="<SCRIPT>SetDefaultDate()</SCRIPT>">
> </TD>
> </TR>
>
>
> I just want to default the html control to todays date.
>
> Why is this all so painful......maybe time for a career change :(

1) size="1" does nothing useful

2) maxlength="50" does nothing

3) SELECT does not support "value="

4) You cannot assign a form value with JavScript in that manner.

5) Are you sure you want a SELECT?

Perhpas you want; (watch for word-wrap):

<script language="javascript" type="text/javascript">
<!--
var html = "<input type='text' name='BatchStartDate' size='10'
maxlength='10' value='";
var when = new Date();
html += when.getMonth()+1 + "/";
html += when.getDate() + "/";
html += when.getFullYear() + "'>";
document.write(html);
// -->
</script>
Note that the month and day will have leading zeroes suppressed; thus New Year's Day will be shown as "1/1/2004".



Jul 20 '05 #11

P: n/a
I found the value='";
Interesting, why the ;
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:iW********************@ursa-nb00s0.nbnet.nb.ca...
Yes

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:iVjEb.423032$ao4.1356533@attbi_s51...
Did you see the code at the bottom of my response?

"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:pz********************@ursa-nb00s0.nbnet.nb.ca...
Sorry guys, you are right, I don't want a select, cut and paste error. I wanted the following:

function SetDefaultDate() {
rightnow = new Date("Month dd, yyyy");
return rightnow;
}

<TD align=left> <input type="text" name="batchStartDate" size="20"
maxlength="50" value="SetDefaultDate()">
However it still does not work, sorry for the confusion

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:trjEb.143715$_M.713535@attbi_s54...
> "Brent Eamer" <be****@islandtelecom.com> wrote in message
> news:cI********************@ursa-nb00s0.nbnet.nb.ca...
> > function SetDefaultDate() {
> > d = new Date();
> > return d;
> > }
> > .......
> > <TD align=left> Start Date: </TD>
> > <TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50" > > value="<SCRIPT>SetDefaultDate()</SCRIPT>">
> > </TD>
> > </TR>
> >
> >
> > I just want to default the html control to todays date.
> >
> > Why is this all so painful......maybe time for a career change :(
>
> 1) size="1" does nothing useful
>
> 2) maxlength="50" does nothing
>
> 3) SELECT does not support "value="
>
> 4) You cannot assign a form value with JavScript in that manner.
>
> 5) Are you sure you want a SELECT?
>
>
>
> Perhpas you want; (watch for word-wrap):
>
> <script language="javascript" type="text/javascript">
> <!--
> var html = "<input type='text' name='BatchStartDate' size='10'
> maxlength='10' value='";
> var when = new Date();
> html += when.getMonth()+1 + "/";
> html += when.getDate() + "/";
> html += when.getFullYear() + "'>";
> document.write(html);
> // -->
> </script>
>
>
> Note that the month and day will have leading zeroes suppressed;
thus New
> Year's Day will be shown as "1/1/2004".
>
>



Jul 20 '05 #12

P: n/a
@SM wrote on 18 Dec 2003 at Thu, 18 Dec 2003 14:57:22 GMT:
may be ... ?

value="<SCRIPT>document.write(SetDefaultDate())</SCRIPT>">


Umm, no. I think you need to review your knowledge of HTML, too.

See my other post.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #13

P: n/a
The variable "html" is be "constructed"; the "document.write()" statement
will display:

<input type='text' name='BatchStartDate' size='10' maxlength='10'
value='12/18/2003'>";
Just cut-and-paste the code into a Web page and try it -- it works as-is.
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:5X********************@ursa-nb00s0.nbnet.nb.ca...
I found the value='";
Interesting, why the ;
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:iW********************@ursa-nb00s0.nbnet.nb.ca...
Yes

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:iVjEb.423032$ao4.1356533@attbi_s51...
Did you see the code at the bottom of my response?

"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:pz********************@ursa-nb00s0.nbnet.nb.ca...
> Sorry guys, you are right, I don't want a select, cut and paste error.
I
> wanted the following:
>
> function SetDefaultDate() {
> rightnow = new Date("Month dd, yyyy");
> return rightnow;
> }
>
> <TD align=left> <input type="text" name="batchStartDate" size="20"
> maxlength="50" value="SetDefaultDate()">
>
>
> However it still does not work, sorry for the confusion
>
> "McKirahan" <Ne**@McKirahan.com> wrote in message
> news:trjEb.143715$_M.713535@attbi_s54...
> > "Brent Eamer" <be****@islandtelecom.com> wrote in message
> > news:cI********************@ursa-nb00s0.nbnet.nb.ca...
> > > function SetDefaultDate() {
> > > d = new Date();
> > > return d;
> > > }
> > > .......
> > > <TD align=left> Start Date: </TD>
> > > <TD align=left> <SELECT name="batchStartDate" size="1"

maxlength="50"
> > > value="<SCRIPT>SetDefaultDate()</SCRIPT>">
> > > </TD>
> > > </TR>
> > >
> > >
> > > I just want to default the html control to todays date.
> > >
> > > Why is this all so painful......maybe time for a career change
:( > >
> > 1) size="1" does nothing useful
> >
> > 2) maxlength="50" does nothing
> >
> > 3) SELECT does not support "value="
> >
> > 4) You cannot assign a form value with JavScript in that manner. > >
> > 5) Are you sure you want a SELECT?
> >
> >
> >
> > Perhpas you want; (watch for word-wrap):
> >
> > <script language="javascript" type="text/javascript">
> > <!--
> > var html = "<input type='text' name='BatchStartDate' size='10'
> > maxlength='10' value='";
> > var when = new Date();
> > html += when.getMonth()+1 + "/";
> > html += when.getDate() + "/";
> > html += when.getFullYear() + "'>";
> > document.write(html);
> > // -->
> > </script>
> >
> >
> > Note that the month and day will have leading zeroes suppressed;

thus New
> > Year's Day will be shown as "1/1/2004".
> >
> >
>
>



Jul 20 '05 #14

P: n/a
Sorry, "is be" should have been "is being".
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:ykkEb.144172$_M.714547@attbi_s54...
The variable "html" is be "constructed"; the "document.write()" statement
will display:

<input type='text' name='BatchStartDate' size='10' maxlength='10'
value='12/18/2003'>";
Just cut-and-paste the code into a Web page and try it -- it works as-is.
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:5X********************@ursa-nb00s0.nbnet.nb.ca...
I found the value='";
Interesting, why the ;
"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:iW********************@ursa-nb00s0.nbnet.nb.ca...
Yes

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:iVjEb.423032$ao4.1356533@attbi_s51...
> Did you see the code at the bottom of my response?
>
> "Brent Eamer" <be****@islandtelecom.com> wrote in message
> news:pz********************@ursa-nb00s0.nbnet.nb.ca...
> > Sorry guys, you are right, I don't want a select, cut and paste error.
I
> > wanted the following:
> >
> > function SetDefaultDate() {
> > rightnow = new Date("Month dd, yyyy");
> > return rightnow;
> > }
> >
> > <TD align=left> <input type="text" name="batchStartDate" size="20"
> > maxlength="50" value="SetDefaultDate()">
> >
> >
> > However it still does not work, sorry for the confusion
> >
> > "McKirahan" <Ne**@McKirahan.com> wrote in message
> > news:trjEb.143715$_M.713535@attbi_s54...
> > > "Brent Eamer" <be****@islandtelecom.com> wrote in message
> > > news:cI********************@ursa-nb00s0.nbnet.nb.ca...
> > > > function SetDefaultDate() {
> > > > d = new Date();
> > > > return d;
> > > > }
> > > > .......
> > > > <TD align=left> Start Date: </TD>
> > > > <TD align=left> <SELECT name="batchStartDate" size="1"
maxlength="50"
> > > > value="<SCRIPT>SetDefaultDate()</SCRIPT>">
> > > > </TD>
> > > > </TR>
> > > >
> > > >
> > > > I just want to default the html control to todays date.
> > > >
> > > > Why is this all so painful......maybe time for a career change

:( > > >
> > > 1) size="1" does nothing useful
> > >
> > > 2) maxlength="50" does nothing
> > >
> > > 3) SELECT does not support "value="
> > >
> > > 4) You cannot assign a form value with JavScript in that manner. > > >
> > > 5) Are you sure you want a SELECT?
> > >
> > >
> > >
> > > Perhpas you want; (watch for word-wrap):
> > >
> > > <script language="javascript" type="text/javascript">
> > > <!--
> > > var html = "<input type='text' name='BatchStartDate' size='10'
> > > maxlength='10' value='";
> > > var when = new Date();
> > > html += when.getMonth()+1 + "/";
> > > html += when.getDate() + "/";
> > > html += when.getFullYear() + "'>";
> > > document.write(html);
> > > // -->
> > > </script>
> > >
> > >
> > > Note that the month and day will have leading zeroes suppressed;

thus
> New
> > > Year's Day will be shown as "1/1/2004".
> > >
> > >
> >
> >
>
>



Jul 20 '05 #15

P: n/a
Brent Eamer wrote:
I found the value='";
Interesting, why the ;


All JavaScript lines should end in semicolons.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #16

P: n/a
In article <MP************************@news.pop4.net>, Chris Smith
<cd*****@twu.net> writes:
Brent Eamer wrote:
I found the value='";
Interesting, why the ;


All JavaScript lines should end in semicolons.


Are you positive about that? semicolons at the ends of some lines will break
the code. Consider:

for (i=0;i<31;i++);
{;
alert(i);
};

I use that format when nesting for loops (and if statements) so I can keep
track of opened and closed { }. The semicolon at the end of the for statement
utterly breaks it. Without the ;, you get 31 alerts, starting from 0 to 30, as
it should be. With the semicolon there, you get one alert (31), which is not
what the code is intended to do.
--
Randy
Jul 20 '05 #17

P: n/a
> >All JavaScript lines should end in semicolons.
Are you positive about that? semicolons at the ends of some lines will break
the code. Consider:

for (i=0;i<31;i++);
{;
alert(i);
};

I use that format when nesting for loops (and if statements) so I can keep
track of opened and closed { }. The semicolon at the end of the for statement
utterly breaks it. Without the ;, you get 31 alerts, starting from 0 to 30, as
it should be. With the semicolon there, you get one alert (31), which is not
what the code is intended to do.


You are correct. Brent should have said that statements should end with
semicolons. JSLINT can help you place them correctly. You also demonstrated why
if statements should always be used with blocks, and why blocks should not be
used alone. JSLINT checks for those, too.

http://www.crockford.com/javascript/lint.html

Jul 20 '05 #18

P: n/a
McKirahan wrote on 18 Dec 2003 at Thu, 18 Dec 2003 15:22:10 GMT:
Sorry to be picky but...

"now.getMonth()" returns 0 to 11 (not 1 to 12).

You example will display the previous month.


Very good point! I always forget that...

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #19

P: n/a
Douglas Crockford wrote:
You are correct. Brent should have said that statements should end with
semicolons. JSLINT can help you place them correctly. You also demonstrated why
if statements should always be used with blocks, and why blocks should not be
used alone. JSLINT checks for those, too.


Actually, it was me (not Brent) that said lines when I should have said
statements.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #20

P: n/a
<TD align=left>
<SELECT name="batchStartDate" size="1" maxlength="50">
<OPTION><SCRIPT>document.write(GetDefaultDate()) </SCRIPT>
</SELECT>
</TD>

"Brent Eamer" <be****@islandtelecom.com> wrote in message
news:cI********************@ursa-nb00s0.nbnet.nb.ca...
function SetDefaultDate() {
d = new Date();
return d;
}
.......
<TD align=left> Start Date: </TD>
<TD align=left> <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>">
</TD>
</TR>
I just want to default the html control to todays date.

Why is this all so painful......maybe time for a career change :(

Jul 20 '05 #21

P: n/a
McKirahan wrote on 18 Dec 2003 at Thu, 18 Dec 2003 16:14:43 GMT:
Sorry, "is be" should have been "is being".


<snipped vast amounts of unneeded quoting>

Please, will you both:

1) Not top-post (place your comments under or amongst quoted text)
2) Trim quoted material to only what is relavant to your post

I'm not trying to be awkward; these practices are part of
established Usenet etiquette.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #22

P: n/a
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:Xn*******************************@193.38.113. 46...
McKirahan wrote on 18 Dec 2003 at Thu, 18 Dec 2003 16:14:43 GMT:
Sorry, "is be" should have been "is being".


<snipped vast amounts of unneeded quoting>

Please, will you both:

1) Not top-post (place your comments under or amongst quoted text)
2) Trim quoted material to only what is relavant to your post

I'm not trying to be awkward; these practices are part of
established Usenet etiquette.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")

Will do. Thanks for the heads up.

I did not know that one should:
"Trim quoted material to only what is relavant to your post".

P.S. It's spelled "relevant".
Jul 20 '05 #23

P: n/a
In article <cgqEb.82049$8y1.287990@attbi_s52>, "McKirahan" <Ne**@McKirahan.com>
writes:
Will do. Thanks for the heads up.

I did not know that one should:
"Trim quoted material to only what is relavant to your post".

P.S. It's spelled "relevant".


Is this alt.correct.spelling or is it comp.lang.javascript where most of the
posters (regulars), have English as a second (or third/fourth) language? Thats
being very very pedantic to me.
--
Randy
Jul 20 '05 #24

P: n/a
McKirahan wrote on 18 Dec 2003 at Thu, 18 Dec 2003 22:56:08 GMT:
P.S. It's spelled "relevant".


I didn't think it looked right, but I wasn't in the mood to check my
dictionary.

Besides, I'm tired. Leave me alone. :P Hehe

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #25

P: n/a
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:cgqEb.82049$8y1.287990@attbi_s52...
<snip>
--
Michael Winter
<snip> Will do. Thanks for the heads up.

I did not know that one should:
"Trim quoted material to only what is relavant to your post".

<snip>

For future reference, other people's signatures, the part separated from
the body of a post with "-- " (dash-dash-space), is almost never
relevant to a response and so a good candidate for trimming.

Richard.
Jul 20 '05 #26

P: n/a
McKirahan wrote:
"Brent Eamer" <be****@islandtelecom.com> wrote:
[...] <SELECT name="batchStartDate" size="1" maxlength="50"
value="<SCRIPT>SetDefaultDate()</SCRIPT>"> [...]

[...]


1) size="1" does nothing useful


False. size="1" allows only one option to be visible at the same time.
Recent graphical UAs render such a `select' element as dropdown box.
PointedEars
Jul 20 '05 #27

P: n/a
JRS: In article <20***************************@mb-m25.aol.com>, seen in
news:comp.lang.javascript, HikksNotAtHome <hi************@aol.com>
posted at Thu, 18 Dec 2003 23:37:39 :-
In article <cgqEb.82049$8y1.287990@attbi_s52>, "McKirahan" <Ne**@McKirahan.com>
writes:
Will do. Thanks for the heads up.

I did not know that one should:
"Trim quoted material to only what is relavant to your post".

P.S. It's spelled "relevant".


Is this alt.correct.spelling or is it comp.lang.javascript where most of the
posters (regulars), have English as a second (or third/fourth) language? Thats
being very very pedantic to me.

Most of the regulars who have English as a subsequent language are in
fact rather good at it, and it would be a pity to teach them mistakes.

Moreover, when using a search tool, it helps if one knows how the word
was spelt.

Careful spelling should be encouraged; it is worth a sentence from time
to time, though generally not a dedicated article.

While on the subject of usage : the OP should have chosen an informative
subject line, and his headers use the non-standard AST (clueless news-
service in New Brunswick?).

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #28

P: n/a
@SM


Brent Eamer a ecrit :

Sorry guys, you are right, I don't want a select, cut and paste error. I
wanted the following:

function SetDefaultDate() {
rightnow = new Date("Month dd, yyyy");
return rightnow;
}

<TD align=left> <input type="text" name="batchStartDate" size="20"
maxlength="50" value="SetDefaultDate()">

However it still does not work, sorry for the confusion


try that :

<TD align=left> <input type="text" name="batchStartDate" size="20"
maxlength="50" value=""> <script type="text/javascript"><!--
this.form.batchStartDate.value = SetDefaultDate();
// --></script>
Jul 20 '05 #29

This discussion thread is closed

Replies have been disabled for this discussion.