473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't get value into html form field


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
10 2164
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dan baker | last post by:
I am pretty much a newbie with javascript, and would like to get a little clarification on what I can do with an onChange javascript event handler. I have a dynamic page I build with perl and...
6
by: charlie_M | last post by:
I figured out via various help from this forum... EXAMPLE: onClick="document.forms.MYBUTTON.value='SIMPLE';document.forms.submit()" In my CGI I see "MYBUTTON" = "SIMPLE" and this works...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
11
by: newbie | last post by:
i have a form in which a hidden field (initial value as '0', and my javascript set it to '1' when an event is trigged). In the same form, i have a reset field. But I realized that the hidden field...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.