...

View Full Version : Clearing a text box when submit is pressed



Taylor_1978
06-07-2004, 11:06 AM
Hi All...

Here is the html I am using:

<iframe name=chat src=chatserver.php#bottom scrolling=no height=400></iframe>
<form method="post" name="form" target=chat action=chatserver.php#bottom
<input type=text name=message autocomplete=off><input type=submit name=submit value=Send>
</form>

When submit is clicked, the iframe "chat" is reloaded. However, what I need is for the text box to clear.. I assume using onSubmit but do not know how exactly.

Any help would be great appreciated.

Thanks in advance! :thumbsup:

Taylor.

glenngv
06-07-2004, 11:20 AM
When you clear the field onsubmit, that blank field will be the one submitted.

What you can do is put a hidden field that will contain the entered message and then of course in chatserver.php, you should retrieve the value of the hidden field not the visible field.


function clearMsg(f){
f.message2.value = f.message.value;
f.message.value = "";
return true;
}
...
<iframe name=chat src=chatserver.php#bottom scrolling=no height=400></iframe>
<form method="post" name="form" target=chat action=chatserver.php#bottom" onsubmit="clearMsg(this)">
<input type="hidden" name="message2" />
<input type=text name=message autocomplete=off><input type=submit name=submit value=Send>
</form>

But you should also check the original field IF the hidden field is empty. Then if the original field has a value, it means that javascript is disabled and you should take the original value as the input.

Taylor_1978
06-07-2004, 11:40 AM
Thank you very much! Works perfectly!

Taylor. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum