Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    Clearing a text box when submit is pressed

    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!

    Taylor.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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.
    Code:
    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.

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    Thank you very much! Works perfectly!

    Taylor.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •