Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Eric Petzold
Guest
 
Posts: n/a
#1: Jul 23 '05
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+"<b r>");
}
</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>



Lee
Guest
 
Posts: n/a
#2: Jul 23 '05

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


Eric Petzold said:[color=blue]
>
>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+"<b r>");
> }
></script>[/color]

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.

bruce
Guest
 
Posts: n/a
#3: Jul 23 '05

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


"Eric Petzold" <ewpetzold@sympatico.ca> wrote in message news:<Nm8yc.47541$8k4.1021535@news20.bellglobal.co m>...[color=blue]
> 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+"<b r>");
> }
> </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>[/color]


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.
Closed Thread