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

how can i insert a deafult value in an input text box?

P: n/a
for example if I have a box where you should put a date how do I keep
today date inside that box as default?

Jul 17 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
You can do something like this, using the date function of PHP:
http://us3.php.net/date

$html = "<input type=\"text\" value=\"".date("m-d-Y")."\" />";

Jul 17 '05 #2

P: n/a

dsp...@gmail.com wrote:
You can do something like this, using the date function of PHP:
http://us3.php.net/date

$html = "<input type=\"text\" value=\"".date("m-d-Y")."\" />";


I would use single quotes here and avoid so many confusing
backslashes...

$html = '<input type="text" value="' . date("m-d-Y") . '" />';

I find this much easier to read.

Ken

Jul 17 '05 #3

P: n/a
"Ken Robinson" <ke******@rbnsn.com> wrote in news:1113401556.678161.246480
@l41g2000cwc.googlegroups.com:
I would use single quotes here and avoid so many confusing
backslashes...

$html = '<input type="text" value="' . date("m-d-Y") . '" />';

I find this much easier to read.


if we're on an "easier to read" tip, call me crazy, but I prefer to keep my
functions and variables kind of seperate. i'd make it into two lines:

$thedate = date("m-d-Y");
$html = "<input type=\"text\" value=\"$thedate\" />";

Jul 17 '05 #4

P: n/a
Good Man <he***@letsgo.com> wrote:
I would use single quotes here and avoid so many confusing
backslashes...

$html = '<input type="text" value="' . date("m-d-Y") . '" />';

I find this much easier to read.


if we're on an "easier to read" tip, call me crazy, but I prefer to keep my
functions and variables kind of seperate. i'd make it into two lines:

$thedate = date("m-d-Y");
$html = "<input type=\"text\" value=\"$thedate\" />";


With the "easier to read (and write)" (tm) version being:
$html = "<input type='text' value='$thedate' />";

Jul 17 '05 #5

P: n/a
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Daniel Tryba's handwriting:
Good Man <he***@letsgo.com> wrote:
I would use single quotes here and avoid so many confusing
backslashes...

$html = '<input type="text" value="' . date("m-d-Y") . '" />';

I find this much easier to read.


if we're on an "easier to read" tip, call me crazy, but I prefer to
keep my
functions and variables kind of seperate. i'd make it into two lines:

$thedate = date("m-d-Y");
$html = "<input type=\"text\" value=\"$thedate\" />";


With the "easier to read (and write)" (tm) version being:
$html = "<input type='text' value='$thedate' />";


And just to be annoying on this, I always capitalize the HTML tags,
therefore:
$thedate = date("m-d-Y");
$html = "<INPUT type='text' value='$thedate' />";
:)

Cheers
Mike
Jul 17 '05 #6

P: n/a
Micha? Wo?niak <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote:
With the "easier to read (and write)" (tm) version being:
$html = "<input type='text' value='$thedate' />";


And just to be annoying on this, I always capitalize the HTML tags,
therefore:
$thedate = date("m-d-Y");
$html = "<INPUT type='text' value='$thedate' />";
:)


It's an XHTML style element, and xhtml specs say:
http://www.w3.org/TR/xhtml1/#h-4.2

Jul 17 '05 #7

P: n/a
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Daniel Tryba's handwriting:
Micha? Wo?niak <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote:
With the "easier to read (and write)" (tm) version being:
$html = "<input type='text' value='$thedate' />";


And just to be annoying on this, I always capitalize the HTML tags,
therefore:
$thedate = date("m-d-Y");
$html = "<INPUT type='text' value='$thedate' />";
:)


It's an XHTML style element, and xhtml specs say:
http://www.w3.org/TR/xhtml1/#h-4.2


As I said: "I always capitalize HTML tags"
^^^^
and INPUT is also a HTML 4.xx element:
http://www.w3.org/TR/html4/interact/forms.html#h-17.4

Cheers
Mike
Jul 17 '05 #8

P: n/a
and my $.02
I believe the HTML spec requires values surrounded by "s not 's
and in general, my nictpick is to surround strings with 's so that PHP
won't parse them
so, I'll side with Ken's post above:

$thedate = date('m-d-Y');
$html = '<INPUT type="text" value="'.$thedate.'" />';

Jul 17 '05 #9

P: n/a
"BKDotCom" <bk***********@yahoo.com> wrote in news:1113414323.608892.170440
@l41g2000cwc.googlegroups.com:
and my $.02
I believe the HTML spec requires values surrounded by "s not 's
and in general, my nictpick is to surround strings with 's so that PHP
won't parse them
so, I'll side with Ken's post above:


but what are you doing with all your other variables? consistency is a
good thing... are your other variables really using single quotes like:

$name = 'Hank Azaria';
$address = '188 Burlington Road';

??

and if so, what happens when you have a name/address with an apostrophe
(ie: Mike O'Malley living at 87 O'Donell Avenue)? I thought it was good
form to use double-quotes in PHP just about *all* the time?
Jul 17 '05 #10

P: n/a
On 2005-04-13, Good Man <he***@letsgo.com> wrote:
and if so, what happens when you have a name/address with an apostrophe
(ie: Mike O'Malley living at 87 O'Donell Avenue)?
Then you escape it. What happens if you use a double-quoted string and
put a double-quote in it? Same thing.
I thought it was good form to use double-quotes in PHP just about
*all* the time?


Not really. Double-quotes means "evaluate me". Example in "Hello $world"
$world is evaluated. And also if you put in a newline or a tab it will
be "evaluated". Whereas single-quote means "do not evaluate me" so
variables and special characters like newline will not be evaluated.

Wether you use one or the other is primarily a matter of taste in the
cases where you don't use evaluation.

--
Cheers
- Jacob Atzen
Jul 17 '05 #11

P: n/a
Michał Woźniak wrote:
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Daniel Tryba's handwriting:

Micha? Wo?niak <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote:
With the "easier to read (and write)" (tm) version being:
$html = "<input type='text' value='$thedate' />";

And just to be annoying on this, I always capitalize the HTML tags,
therefore:
$thedate = date("m-d-Y");
$html = "<INPUT type='text' value='$thedate' />";
:)


It's an XHTML style element, and xhtml specs say:
http://www.w3.org/TR/xhtml1/#h-4.2

As I said: "I always capitalize HTML tags"
^^^^
and INPUT is also a HTML 4.xx element:
http://www.w3.org/TR/html4/interact/forms.html#h-17.4


Yes, but in that case you should write

"<INPUT type='text' value='$thedate'>"

rather than

"<INPUT type='text' value='$thedate' />"

right?

JP

--
Sorry, <de*****@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Jul 17 '05 #12

P: n/a
One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable Jan Pieter Kunst's handwriting:
Micha│ Wo╝niak wrote:
One quick glance of an experienced eye allowed to understand the
blurred and almost unreadable Daniel Tryba's handwriting:

Micha? Wo?niak <mikiwoz_remove_this@yahoo_remove_this.co.uk> wrote:

>With the "easier to read (and write)" (tm) version being:
>$html = "<input type='text' value='$thedate' />";

And just to be annoying on this, I always capitalize the HTML tags,
therefore:
$thedate = date("m-d-Y");
$html = "<INPUT type='text' value='$thedate' />";
:)

It's an XHTML style element, and xhtml specs say:
http://www.w3.org/TR/xhtml1/#h-4.2

As I said: "I always capitalize HTML tags"
^^^^
and INPUT is also a HTML 4.xx element:
http://www.w3.org/TR/html4/interact/forms.html#h-17.4


Yes, but in that case you should write

"<INPUT type='text' value='$thedate'>"

rather than

"<INPUT type='text' value='$thedate' />"

right?

JP


Ooops, missed that, thanks. :)

Cheers
Mike
Jul 17 '05 #13

P: n/a
BKDotCom <bk***********@yahoo.com> wrote:
I believe the HTML spec requires values surrounded by "s not 's


Nope, either is fine and may even be ommited in this case.
(http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2)

Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.