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

U

ungvichian

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.
 
M

McKirahan

ungvichian said:
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.

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".
 
U

ungvichian

McKirahan said:
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".

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!
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top