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

Can't get value into html form field

P: n/a

Can anyone tell me what I'm doing wrong here?

==================================

<html>
<head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">
</head>

<body>

<script type="text/javascript">
document.EmailFound.CMName.value="Fanny";
</script>

<form method="POST" name="EmailFound" id="EmailFound">
<input name="CMName" />
<input type="submit" value="Submit" name="submit" />
</form>

</body>

</html>

==================================

"Fanny" will not appear in the input field.
Jul 18 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Kelly wrote:
Can anyone tell me what I'm doing wrong here?

==================================

<html>
Missing doctype declaration.
http://www.htmlhelp.com/tools/validator/doctype.html
<head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">
<scripttag not closed.
</head>

<body>

<script type="text/javascript">
document.EmailFound.CMName.value="Fanny";
</script>
document.EmailFound.CMName is not an object yet at this point of the
code execution. The basic flow is still top-down.

For a better backwards compatibility, one could also use:

document.forms['EmailFound'].elements['CMName'].value

in stead of

document.EmailFound.CMName.value
<form method="POST" name="EmailFound" id="EmailFound">
<input name="CMName" />
Though not strictly required, this should be <input type="text"
name="CMName">.
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
All together:

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form</title>
</head>
<body
onLoad="document.EmailFound.CMName.value='Fanny';" >
<form method="POST" name="EmailFound">
<input type="text" name="CMName">
<input type="submit" value="Submit">
</form>
</body>
</html>

The 'onLoad' event handler is executed right after the page has fully
loaded.

Hope this helps,

--
Bart
Jul 18 '08 #2

P: n/a
On Jul 18, 4:45*pm, Kelly <jor...@pobox.comwrote:
Can anyone tell me what I'm doing wrong here?

"Fanny" will not appear in the input field.
<html>
<head>
<title>Test Form</title>
</head>
<body>
<form method="POST" name="EmailFound" id="EmailFound">
<input name="CMName" />
<input type="submit" value="Submit" name="submit" />
</form>
<script type="text/javascript">
document.EmailFound.CMName.value="Fanny";
</script>
</body>
</html>

--Jorge
Jul 18 '08 #3

P: n/a
On Jul 18, 11:12*am, Jorge <jo...@jorgechamorro.comwrote:
On Jul 18, 4:45*pm, Kelly <jor...@pobox.comwrote:
Can anyone tell me what I'm doing wrong here?
"Fanny" will not appear in the input field.

<html>
<head>
*<title>Test Form</title>
</head>
<body>
*<form method="POST" name="EmailFound" id="EmailFound">
* *<input name="CMName" />
* *<input type="submit" value="Submit" name="submit" />
*</form>
*<script type="text/javascript">
*document.EmailFound.CMName.value="Fanny";
*</script>
</body>
</html>

--Jorge
Thank you both, it works great!

But now that I want to put back some of the code I stripped out for
the example, I can't get it to work again.

I don't want "Fanny" to be hardcoded, but to be returned from a
function call. Here is the adjusted code with a stripped-down
function:

=================================================

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form</title>
</head>

<script type="text/javascript">
function getValue();
return "Fanny";
</script>

<body
<form method="POST" name="EmailFound">
<input type="text" name="CMName">
<input type="submit" value="Submit">
</form>

<script type="text/javascript">
document.EmailFound.CMName.value=getvalue();
</script>

</body>
</html>

=================================================

Jul 18 '08 #4

P: n/a
On Jul 18, 12:59*pm, jora...@gmail.com wrote:
On Jul 18, 11:12*am, Jorge <jo...@jorgechamorro.comwrote:


On Jul 18, 4:45*pm, Kelly <jor...@pobox.comwrote:
Can anyone tell me what I'm doing wrong here?
"Fanny" will not appear in the input field.
<html>
<head>
*<title>Test Form</title>
</head>
<body>
*<form method="POST" name="EmailFound" id="EmailFound">
* *<input name="CMName" />
* *<input type="submit" value="Submit" name="submit" />
*</form>
*<script type="text/javascript">
*document.EmailFound.CMName.value="Fanny";
*</script>
</body>
</html>
--Jorge

Thank you both, it works great!

But now that I want to put back some of the code I stripped out for
the example, I can't get it to work again.

I don't want "Fanny" to be hardcoded, but to be returned from a
function call. *Here is the adjusted code with a stripped-down
function:

=================================================

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
*"http://www.w3.org/TR/html4/strict.dtd">
*<html>
* <head>
* *<title>Test Form</title>
* </head>

<script type="text/javascript">
* function getValue();
* return "Fanny";
</script>

*<body
* <form method="POST" name="EmailFound">
* *<input type="text" name="CMName">
* *<input type="submit" value="Submit">
* </form>

* <script type="text/javascript">
* * document.EmailFound.CMName.value=getvalue();
* </script>

*</body>
*</html>

=================================================- Hide quoted text -

- Show quoted text -
Note, that should read <body>
Jul 18 '08 #5

P: n/a
On Jul 18, 6:59*pm, jora...@gmail.com wrote:
>
But now that I want to put back some of the code I stripped out for
the example, I can't get it to work again.
<html>
<head>
<title>Test Form</title>
<script type="text/javascript">
function getValue () {
return "Fanny";
};
</script>
</head>
<body>
<form method="POST" name="EmailFound">
<input type="text" name="CMName">
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
document.EmailFound.CMName.value= getValue();
</script>
</body>
</html>

--Jorge.
Jul 18 '08 #6

P: n/a
Bart Van der Donck wrote:
Kelly wrote:
>Can anyone tell me what I'm doing wrong here?
[...]
<html>

Missing doctype declaration.
^^^^^^^
See below.
http://www.htmlhelp.com/tools/validator/doctype.html
><head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">

<scripttag not closed.
The <scripttag was closed, with `>'. However, the `script' *element* was
not closed/ended (with the corresponding </scriptend tag). And the
`language' attribute is deprecated.
>[...]
document.EmailFound.CMName.value="Fanny";
[...]

[...]
For a better backwards compatibility, one could also use:

document.forms['EmailFound'].elements['CMName'].value

in stead of

document.EmailFound.CMName.value
Backwards compatibility is _not_ the reason why collections should be used
instead; both approaches are equally backwards-compatible. This is instead
about standards compliance: HTML collections are a specified Web standard
(per W3C DOM Level 2 HTML); shorthand references like these are not.
><form method="POST" name="EmailFound" id="EmailFound">
Not Valid, the required `action' attribute is missing.
><input name="CMName" />
See below.
Though not strictly required, this should be <input type="text"
name="CMName">.
Why? TEXT is the default value for the `type' attribute of the HTML INPUT
element, and `text' is the default value of the XHTML `input' element.

I know of no non-obsolete user agent that requires this default value to be
set explicitly for the element to be considered a text input control. Do you?
><input type="submit" value="Submit" name="submit" />
<.../is XML syntax supported for elements with EMPTY content model in
XHTML (an application of XML), not in HTML (an application of SGML).
></form>
</body>
</html>

All together:

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
Strange, I thought SGML keywords are case-sensitive, i.e. "DOCTYPE". Is
this a (W3C) Validator bug not recognizing the error, or has there been a
(W3C) Validator bug before, that is now fixed, which marked the lowercase
version as such?
[...]
<body
onLoad="document.EmailFound.CMName.value='Fanny';" >
Have you not just suggested the standards-compliant solution?

onload="document.forms['EmailFound'].elements['CMName'].value='Fanny';">
<form method="POST" name="EmailFound">
<input type="text" name="CMName">
<input type="submit" value="Submit">
</form>
This is, again, _not_ Valid HTML 4.01 Strict. The required `action'
attribute is missing and the inline-level `input' elements must be
descendants of another block-level element for this.
[...]
The 'onLoad' event handler is executed right after the page has fully
loaded.
The *value* of the intrinsic `onload' event handler _attribute_ is then
passed to the script engine and executed as a program by it.
--
Your signature delimiter has been broken by Google Groups; the necessary
trailing space was removed. I suggest not to use signatures with user
agents this broken. (Or, even better, not to use those applications for
posting at all.)
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jul 18 '08 #7

P: n/a
jora...@gmail.com wrote:
...
But now that I want to put back some of the code I stripped out for
the example, I can't get it to work again.

I don't want "Fanny" to be hardcoded, but to be returned from a
function call. *Here is the adjusted code with a stripped-down
function:

=================================================

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
*"http://www.w3.org/TR/html4/strict.dtd">
*<html>
* <head>
* *<title>Test Form</title>
* </head>

<script type="text/javascript">
* function getValue();
* return "Fanny";
</script>
*<body
* <form method="POST" name="EmailFound">
* *<input type="text" name="CMName">
* *<input type="submit" value="Submit">
* </form>
* <script type="text/javascript">
* * document.EmailFound.CMName.value=getvalue();
* </script>
*</body>
*</html>
These are all very basic instructions. I think you need a javascript
tutorial.

--
Bart
Jul 18 '08 #8

P: n/a
On Jul 18, 1:16*pm, Bart Van der Donck <b...@nijlen.comwrote:
jora...@gmail.com wrote:
...
But now that I want to put back some of the code I stripped out for
the example, I can't get it to work again.
I don't want "Fanny" to be hardcoded, but to be returned from a
function call. *Here is the adjusted code with a stripped-down
function:
=================================================
<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
*"http://www.w3.org/TR/html4/strict.dtd">
*<html>
* <head>
* *<title>Test Form</title>
* </head>
<script type="text/javascript">
* function getValue();
* return "Fanny";
</script>
*<body
* <form method="POST" name="EmailFound">
* *<input type="text" name="CMName">
* *<input type="submit" value="Submit">
* </form>
* <script type="text/javascript">
* * document.EmailFound.CMName.value=getvalue();
* </script>
*</body>
*</html>

These are all very basic instructions. I think you need a javascript
tutorial.

--
*Bart- Hide quoted text -

- Show quoted text -
Thank you both for your help. My page is much more complicated than
shown but I narrowed it down to just the problem area. It's all
working fine now!

I agree that I really need to learn javascript from the ground up. As
usual, I was given a task that has to be done today ... no time to
learn!

Jul 18 '08 #9

P: n/a
Thomas 'PointedEars' Lahn wrote:
Bart Van der Donck wrote:
><scripttag not closed.

The <scripttag was closed, with `>'. *However, the `script' *element*was
not closed/ended (with the corresponding </scriptend tag). *
To be precise with W3-compliant terminology, <scriptis the Start Tag
and </scriptthe End Tag of the Element. For me that makes sense to
state that the Start Tag was thus not closed.
And the `language' attribute is deprecated.
I'm not exactly looking forward to a 99th discussion about this issue.
>For a better backwards compatibility, one could also use:
*document.forms['EmailFound'].elements['CMName'].value
in stead of
*document.EmailFound.CMName.value

Backwards compatibility is _not_ the reason why collections should be used
instead; both approaches are equally backwards-compatible. *This is instead
about standards compliance: HTML collections are a specified Web standard
(per W3C DOM Level 2 HTML); shorthand references like these are not.
<form method="POST" name="EmailFound" id="EmailFound">

Not Valid, the required `action' attribute is missing.
Yes, I should've validated the page at validator.w3.org so that I
wouldn't have overlooked it.
>><input name="CMName" />
Though not strictly required, this should be <input type="text"
name="CMName">.

Why? *TEXT is the default value for the `type' attribute of the HTML INPUT
element, and `text' is the default value of the XHTML `input' element.
We discussed this before and my position has remained unchanged.
Adding 'type="text"' has only benefits and helps to make the code
clearer and self-explanatory.
I know of no non-obsolete user agent that requires this default value to be
set explicitly for the element to be considered a text input control. *Do you?
Netscape 4. Your choice to decide if that's obsolete enough for you.
>><input type="submit" value="Submit" name="submit" />

<.../is XML syntax supported for elements with EMPTY content model in
XHTML (an application of XML), not in HTML (an application of SGML).
>></form>
</body>
</html>
>All together:
><!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
*"http://www.w3.org/TR/html4/strict.dtd">

Strange, I thought SGML keywords are case-sensitive, i.e. "DOCTYPE". *Is
this a (W3C) Validator bug not recognizing the error, or has there been a
(W3C) Validator bug before, that is now fixed, which marked the lowercase
version as such?
I'm not aware of that. But DOCTYPE is recommended, yes.
>[...]
*<body
* onLoad="document.EmailFound.CMName.value='Fanny';" >

Have you not just suggested the standards-compliant solution?

* onload="document.forms['EmailFound'].elements['CMName'].value='Fanny';">
>* <form method="POST" name="EmailFound">
* *<input type="text" name="CMName">
* *<input type="submit" value="Submit">
* </form>

This is, again, _not_ Valid HTML 4.01 Strict. *The required `action'
attribute is missing
Yes, you already mentioned that in your previous paragraph.

--
Bart
Jul 18 '08 #10

P: n/a
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
>Bart Van der Donck wrote:
>><scripttag not closed.
The <scripttag was closed, with `>'. However, the `script' *element* was
not closed/ended (with the corresponding </scriptend tag).

To be precise with W3-compliant terminology,
I would not be so sure about that. SGML was there before TBL invented HTML
to begin with.
<scriptis the Start Tag and </scriptthe End Tag of the Element.
I think I just said that.
For me that makes sense to state that the Start Tag was thus not closed.
An SGML tag is opened with `<' (STAGO: Start TAG Open delimiter) and closed
with `>' (TAGC: TAG Close delimiter). An SGML element is started with
`<...>' (start tag) and ended with `</...>' (end tag, beginning with the --
at least for script authors -- well-known ETAGO [End TAG Open delimiter]
`</' and ending with a TAGC).

See also <http://xml.coverpages.org/sgmlsyn/sgmlsyn.htm#C7.4>.

But I accept your explanation for the choice of terminology.
>And the `language' attribute is deprecated.

I'm not exactly looking forward to a 99th discussion about this issue.
Nevertheless, if you suggest to the OP to use HTML 4.01 *Strict*, it might
be a good idea to mention this fact in at least a line, since the resulting
markup would be invalid then. Deprecation of markup tokens, at least, is
not merely a matter of opinion, but of syntax.
>>><input name="CMName" />
Though not strictly required, this should be <input type="text"
name="CMName">.
Why? TEXT is the default value for the `type' attribute of the HTML INPUT
element, and `text' is the default value of the XHTML `input' element.

We discussed this before and my position has remained unchanged.
Adding 'type="text"' has only benefits
Such as?
and helps to make the code clearer and self-explanatory.
Text input comes first to my mind when talking about input, so I don't need
the reminder. YMMV.
>I know of no non-obsolete user agent that requires this default value to be
set explicitly for the element to be considered a text input control. Do you?

Netscape 4. Your choice to decide if that's obsolete enough for you.
IIRC I have showed before that it is _not_ an issue with Netscape 4.x.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jul 18 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.