Page 1 of 1

clear form

Posted: Tue May 03, 2005 11:48 pm
by s.dot
I need to clear a form after submitting the info, which I clear on the page that processes the info. However, firefox doesn't like the way I coded it I guess, so I need to figure out how to clear the info after the user hits the enter button (or clicks the submit button)

how would I do that?
the function I need to call is parent.resetForm();

Posted: Tue May 03, 2005 11:49 pm
by hawleyjr
Please post your code...

Posted: Wed May 04, 2005 12:03 am
by s.dot

Code: Select all

<?
require 'important.php';
if(!isset($_COOKIE&#1111;'username'])){ die(); }
if($_COOKIE&#1111;'username'] == &quote;&quote;){ die(); }
if($_POST&#1111;'message'] == &quote;&quote;){ die(); }

if(sizeof($_POST&#1111;'message'])){ ?>
<script type=&quote;text/javascript&quote;>
<!--
if(parent.resetForm)
parent.resetForm();
//-->
</script><? } ?>
This is *part* of the page that processes the posted info. The parent.resetForm works in IE, but not in firefox. If you need to see the whole page I will post it.

...

Posted: Wed May 04, 2005 12:20 am
by Calimero
You can do it both in php or JavaScript, do you want to clear it when the data is added to database, or just want to clear it for the user to see immidiately after clicking enter.

Is the first option what you need ?


(just note - if you use Javascript in a newly loaded page, you can reference a form, only after it was loaded, you must leave javascript code after loading a form)

Posted: Wed May 04, 2005 1:25 am
by s.dot
this is part of a php/javascript chat script.
The user posts his/her message, adds to database, displays it for everyone to see.
So I guess I would need it to clear after submitting data to the page.. which is what it does now in IE.

(extra question.. if I did an onkeypress or onclick event handler on the form to clear the data, would it actually submit any information?)

...

Posted: Wed May 04, 2005 1:49 am
by Calimero
For the NOTE - go try - it should submit nothing ( to some sense, but the safest way is to run it )

For the script:

You don't need JavaScript part, only PHP that does not echo ( fill the fields ) the data inputed to the fields again, so remove ( if you have ) any similar code and data will be submited and the textfields or textareas will remain blank.

That should be strait forward.

Although, I would add this JavaScript - to prevent BACK button bug.

on_load event - empty all fields ( that are textfield or textarea) and set default values for radio and select elements.

Does this resolves your problem.

And for the php part - do you need to redirect the user to the same page - it would be much wiser to redirect him/her to a REPORT page that will, with HTML redirection go to forum and preview the message.

There give the user the option of posting a new message.