Why does this fail via onSubmit, but work otherwise??

E

Eric Petzold

This is a small excerpt of a larger script, but it is creating alot of
frustration. I am trying to query the vaule of a hidden form field via
onSubmit... if the function gets called out-right it works okay, but if it
gets called onSubmit, only the first form field value gets displayed and the
rest are undefined.

Help!

<script>
function showValues() {
document.write(document.project.number.value+"<br>");
document.write(document.project.createdOn.value+"<br>");
document.write(document.project.closedOn.value+"<br>");
}
</script>

<form method="POST" name="project" onSubmit="showValues();">
<input type="hidden" name="number" value="2004000">
<input type="hidden" name="createdOn" value="yesterday">
<input type="hidden" name="closedOn" value="tomorrow">

<input type="submit">
</form>

<script>showValues();</script>
 
L

Lee

Eric Petzold said:
This is a small excerpt of a larger script, but it is creating alot of
frustration. I am trying to query the vaule of a hidden form field via
onSubmit... if the function gets called out-right it works okay, but if it
gets called onSubmit, only the first form field value gets displayed and the
rest are undefined.

Help!

<script>
function showValues() {
document.write(document.project.number.value+"<br>");
document.write(document.project.createdOn.value+"<br>");
document.write(document.project.closedOn.value+"<br>");
}
</script>

Once the page has been completely rendered, calling document.write()
clears the current contents and begins writing a new page.
By the time the second document.write() tries to execute, your
form has been deleted.
 
B

bruce

Eric Petzold said:
This is a small excerpt of a larger script, but it is creating alot of
frustration. I am trying to query the vaule of a hidden form field via
onSubmit... if the function gets called out-right it works okay, but if it
gets called onSubmit, only the first form field value gets displayed and the
rest are undefined.

Help!

<script>
function showValues() {
document.write(document.project.number.value+"<br>");
document.write(document.project.createdOn.value+"<br>");
document.write(document.project.closedOn.value+"<br>");
}
</script>

<form method="POST" name="project" onSubmit="showValues();">
<input type="hidden" name="number" value="2004000">
<input type="hidden" name="createdOn" value="yesterday">
<input type="hidden" name="closedOn" value="tomorrow">

<input type="submit">
</form>

<script>showValues();</script>


The use of "document.write" is always very much abused, as I see
from reading these newsgroups. As the prior gentleman said, the act of
using this, has cleared the page, and the form no longer exists.
I've been writing javascript for almost 7 years, and have yet to
have the need, in a business application, for using "document.write".
Frankly, I don't understand all these attempts to use it.
Our normal mode of operation here is to create a web page thru
html, and then to show/hide fields (using javascript) as the need
occurs. Either this, or use innerText and innerHTML properties of a
<SPAN> tag to create more dynamic pages. In any case "document.write"
has never been used a single time in thousands of lines of javascript.
And from what I see in this newsgroup, it's been a sound decision.
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top