Can't get value into html form field

K

Kelly

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.
 
B

Bart Van der Donck

Kelly said:
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">

</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,
 
J

Jorge

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
 
J

jorabi1

<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>

=================================================
 
J

jorabi1

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>
 
J

Jorge

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.
 
T

Thomas 'PointedEars' Lahn

Bart said:
Kelly said:
Can anyone tell me what I'm doing wrong here?
[...]
<html>

Missing doctype declaration.
^^^^^^^
See below.

The <script> tag was closed, with `>'. However, the `script' *element* was
[...]
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.

Not Valid, the required `action' attribute is missing.

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?
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
 
B

Bart Van der Donck

...
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.
 
J

jorabi1

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

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!
 
B

Bart Van der Donck

Thomas said:
The <script> tag was closed, with `>'.  However, the `script' *element*was
not closed/ended (with the corresponding </script> end tag).  

To be precise with W3-compliant terminology, <script> is the Start Tag
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.

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.
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.
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.
 
T

Thomas 'PointedEars' Lahn

Bart said:
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.
<script> is the Start Tag and </script> the 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.
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.
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.
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
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top