clear form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

clear form

Post 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();
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Please post your code...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post 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)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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?)
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post 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.
Post Reply