Two JS questions in one: giving focus, and clearing form (read inside)

Discussion in 'Javascript' started by ungvichian, May 25, 2005.

  1. ungvichian

    ungvichian Guest

    Okay, how do I write a page with a form so that when I click Submit,
    the following happens?

    1. The data is submitted (of course)
    2. The form is cleared (what I've tried results in the form being
    cleared first, resulting in an empty submission), and
    3. The cursor goes back to the start of the form, ready for more input
    (kind of like how Google puts the cursor in the search box at the
    start).

    I can't seem to find the answer, and I've been looking on the net for a
    few hours already.
     
    ungvichian, May 25, 2005
    #1
    1. Advertisements

  2. ungvichian

    McKirahan Guest

    Say your page is like this:

    <html>
    <head>
    <title>page1.htm</title>
    </head>
    <body onload="document.form1.first.focus()">
    <form action="page2.htm" method="get" name="form1">
    <input type="text" name="first">
    <input type="text" name="second">
    <input type="text" name="third">
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>

    When "page2.htm" is done processing the form just have it call "page1.htm".
     
    McKirahan, May 25, 2005
    #2
    1. Advertisements

  3. ungvichian

    ungvichian Guest

    I've adapted your solution, but I made it so that the submit button
    simply reloads the form upon submission (and I found that at another
    page). Source:

    <body onload="document.input.id.focus()">
    <form name = "input" method = "post" action = "<?php echo
    $_SERVER['PHP_SELF'];?>" target=content>
    ID: <input type="Text" name="id" size=7 maxlength=7> <input
    type="Submit" name="submit" value="Submit"
    OnClick="window.location.replace(
    unescape(window.location.pathname));"></form></body>

    Thank you!
     
    ungvichian, May 26, 2005
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.