How to clear form, after submit, but after data passed?

Alright here is the problem.

I have a text field,a submit button, and an iframe on the page.

The form targets the iframe, so I pass data to it, by entering text into the field, and hitting enter, or clicking submit…

data is passed, BUT for some reason, the text field does not clear… I’ve tried doing onSubmit with a function to clear data, but that is before the data gets passed, so no data is passed, because of the function, i’ve been trying other ways, but it doesn’t seem to be working, does anyone else have any idea?


function clearForm() {
if(document.getElementById) {
document.myForm.reset();
}
}

cheers :slight_smile:

um that did not work, here is the actual code for the page…


<html>
<head>
<title>Main</title>
<style type="text/css">
.chatbar {
   width: 650px;
}
</style>
<script type="text/javascript">
function clearField() {
   if(document.getElementById) {
      document.chatform.reset();
   }
}
</script>
</head>
<body>
<center>
<br><br><br>
<form name="chatform" id="chatform" method="POST" target="chat" action="chat.php" onSubmit="clearField();">
<input type="text" id="message" name="message" value="" class="chatbar">
<input type="submit" name="submit" value="Send Message">
</form>
<br><br>
<iframe class="chat" name="chat" width="800px" height="500px" src="chat.php" align=center frameborder=10> </iframe>
</center>
</body>
</html>

I still can not figure it out :frowning:

u have to call the function with submit button!

onClick="clearField();"

or just this…


function clearField() {
document.chatform.reset();
}

cheers :slight_smile:

um, using the submit button = bad, because Its anytime they submit the form, hit enter, or click on it with their mouse, and its not working still :frowning:

try…


function clearField() {
if(document.getElementById) {
document.chatform.message.value = "";
}
}