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

Discussion in 'Javascript' started by Eric Petzold, Jun 11, 2004.

  1. Eric Petzold

    Eric Petzold Guest

    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>
    Eric Petzold, Jun 11, 2004
    #1
    1. Advertising

  2. Eric Petzold

    Lee Guest

    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.
    Lee, Jun 11, 2004
    #2
    1. Advertising

  3. Eric Petzold

    bruce Guest

    "Eric Petzold" <> wrote in message news:<Nm8yc.47541$>...
    > 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.
    bruce, Jun 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric Woudenberg
    Replies:
    2
    Views:
    675
    Jason Tishler
    Jun 22, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,747
    Smokey Grindel
    Dec 2, 2006
  3. pemo

    c99, but otherwise OT

    pemo, Nov 14, 2005, in forum: C Programming
    Replies:
    5
    Views:
    364
    jacob navia
    Nov 15, 2005
  4. Radu
    Replies:
    0
    Views:
    255
  5. Kingsley Turner
    Replies:
    1
    Views:
    380
    Diez B. Roggisch
    Oct 14, 2010
Loading...

Share This Page