Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form clear on Submit

Status
Not open for further replies.

Hondy

Technical User
Mar 3, 2003
864
GB
Hi

I have a page that submits a user ID and password which launches a new window (it has to do this) - once you log off and close this new browser window the login details are still in the form on the original browser window.

How do you make it so the form clears once the submit button is clicked?

Thanks
 
At the end of the code that opens the new window and passes the information, try

document.forms['formnamehere'].reset();

Lee
 
Code:
<script>
function Submit_Clear(){
if(users.apassword.value=="" || users.aname.value==""){
alert("Enter Value");
return false;
}

window.open("[URL unfurl="true"]http://127.0.0.1/?name="+users.aname.value[/URL] + "&pass=" + users.apassword.value);
users.aname.value="";
users.apassword.value="";
}
</script>


<form id="users"><pre>
 Name:     <input type="text" id="aname" />
 Password: <input type="text" id="apassword" />
 <input type="button" id="sendit" value="Log In" onclick="Submit_Clear();" /></pre>
</form>
 
Hi

Just a small correction :
Code:
window.open("[URL unfurl="true"]http://127.0.0.1/?name="+[/URL][red]escape([/red]users.aname.value[red])[/red] + "&pass=" + [red]escape([/red]users.apassword.value[red])[/red]);

Feherke.
 
ok thanks fendal and feherke, I have it clearing the form but it doesn't pass the details onto the new window, I think because of the post part of the form on my page. Can you explain why the script hasn't got a "post" on the form anymore?
 
Hi

Sadly, the post mechanism needs more contribution of the browser, this simple solution is suitable only for get. Probably can do a post using some DOM objects, but no proper idea.

The easy way is to use the form itself for this. Sincerely, I do not got the point, what you try to do exactly. Please give us an URL, if your current draft is available on-line.

Feherke.
 
I have it clearing the form but it doesn't pass the details onto the new window

Is that because it's being cleared before it can be posted ?, you could try making hidden inputs, the username and password will still be there, just not seen.

Code:
<html>
<body>
<script type="text/javascript">
function clearit(){
main.name.value="";
main.pass.value="";
//alert(main.Rname.value + "/" + main.Rpass.value);
}
</script>
<form method="post" name="main" id="main">
<pre>
Name:    <input type="text" id="name" onkeyup="Rname.value=this.value">
Password:<input type="text" id="pass" onkeyup="Rpass.value=this.value">
   <input type="submit" Value="Log In" onclick="clearit();">
<input type="hidden" id="Rname">
<input type="hidden" id="Rpass">
</pre>
</form>
</body>
</html>

you'd need to get the value of Rname and Rpass in your new window, this seems long winded, but still..
 
How about showing the code you have already? You originally wrote that you open a new window, but you mentioned doing a post, which is NOT a new window.

Lee
 

Fendal, yes it's clearing the form before it posts it, almost had it! i'll try your code tomorrow thanks.

trollacious, I can post the code tomorrow, but for now the post target URL is _blank so it posts to a new window, it works fine apart from the fact that when you close the new window I'm left with the details still in the form.
 
Hi

As I know, all form related events will be executed before submiting it's content, so the reset must be done abit later. For example, 1 second after submit :
Code:
<form name="login" action="/cgi-bin/whatever.pl" method="post" target="_blank" onsubmit="setTimeout('document.login.reset()',1000)">
Or, the document returned by the CGI can contain something like :
Code:
<script type="text/javascript">
opener.document.login.reset();
</script>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top