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();
clear form
Moderator: General Moderators
Code: Select all
<?
require 'important.php';
if(!isset($_COOKIEї'username'])){ die(); }
if($_COOKIEї'username'] == "e;"e;){ die(); }
if($_POSTї'message'] == "e;"e;){ die(); }
if(sizeof($_POSTї'message'])){ ?>
<script type="e;text/javascript"e;>
<!--
if(parent.resetForm)
parent.resetForm();
//-->
</script><? } ?>...
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)
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)
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?)
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?)
...
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.
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.