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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear two text fields upon pressing submit button?

Status
Not open for further replies.

jollekox

Programmer
Feb 3, 2004
23
0
0
NO
I have created a perl/cgi script that loads into an iframe on my webpage, displaying text taken from a mysql database. As the form for input of data into the database is on the page that holds the iframe, the text sticks in the fields after the submit button is pressed.

If anyone would help me, I'd be really grateful.

The code I am trying to use is:
<script language="JavaScript">
<!--
function clear(elmtRef,formRef) {    
formRef.name = "";
formRef.message = "";
}
//-->
</script>

<input type="submit" name="post" border="0" onClick="clear(this,this.form );">

Best regards,
jollekox
 
Code:
<html>
<head>
<title>Form manipulation</title>
<script type="text/javascript">
<!-- hide

function submitForm(the_form)
{
  the_form.submit();
  the_form.reset(); // Use to clear all fields
}

// end hide -->
</script>
</head>
<body>
<form name="aform">
<input type="text" name="text1"><br>
<input type="button" value="Submit!" onclick="submitForm(this.form);">
</form>
</body>
</html>

Does that work? I didn't test it, but it should.
How do you submit a form without reloading the page?

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Thanks for a swift reply!

Well, it works, but it clears all fields before the form is sent, wich is a bit bad. a one second time delay would probarbly fix that. The downside, I really don't know that much Javascrip.

How I send the form without reloading? In the form tag i put target="name" to make the cgi script appear in my iframe.

<- It is probarbly easier to understand if
you look at it yourself...
 
I'm awfully sorry, I didn't see that it wasn't a regular submit button in your example.

Thanks a lot for your help.
 
Another version:

Code:
<html>
<head>
<title>Form manipulation</title>
<script type="text/javascript">
<!-- hide

function submitForm(the_form)
{
  the_form.submit();
  the_form.reset(); // Use to clear all fields
}

// end hide -->
</script>
</head>
<body>
<form name="aform" onsubmit="submitForm(this); return false;">
<input type="text" name="text1"><br>
<input type="submit" value="Submit!">
</form>
</body>
</html>

Try this, and add whatever target attribute you need.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
What does the return false do? Not much, in my opinion, IE has a lack of support to loading functions from another IFRAME, as I tried, tonight.

Now, I'm really greatful, and I'm gonna get drunk, so, good night.
End of conversation.
 
Here is the problem with your script: You have two form tags.

Instead of this:
Code:
[red]<form action="cgi-bin/say.cgi" target="content" method="post" name="data">[/red]
<input type="hidden" name="action" value="1">
<div class='text'>You speak:<br>
<input type="text" name="name" value="" size="20" maxlength="20" border="0"><br>
<input type="text" name="message" value="" size="20" maxlength="20" border="0"><br>

[red]<form name="aform" onsubmit="submitForm(this); return false;"> [/red]
<input type="reset" border="0"><br>
</form>

use

Code:
<[red]form action="cgi-bin/say.cgi" target="content" method="post" name="data" onsubmit="submitForm(this); return false;">[/red]
<input type="hidden" name="action" value="1">
<div class='text'>You speak:<br>
<input type="text" name="name" value="" size="20" maxlength="20" border="0"><br>
<input type="text" name="message" value="" size="20" maxlength="20" border="0"><br>
<input type="submit" value="Submit!"><br>
<input type="reset" border="0"><br>
</form>

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top