SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form input text box that doesn't clear?

    Form input text box that doesn't clear?

    Hi all

    Is it possible to have input text area that doesn't clear when a submit button is pressed.
    In this example here - http://www.ttmt.org.uk/form/ if I enter text in the box then click the submit button the text box clears - I want to keep the text in the text box.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    	<title>untitled</title>
    	
    </head>
    
    <body>
      <form action="" method="" >
        
        <input type="text" name="text" />
        <input type="submit" value="Set &rarr;">
      </form>
    
    </body>
    </html>

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are submitting the form to the same web page it is in.

    So one option is to use the form's GET or POST value of the input text area to set the default value for the text area when the page reloads after you have submitted it.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I do that ?

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,601
    Mentioned
    411 Post(s)
    Tagged
    7 Thread(s)
    Are you using PHP to process your form? If so, you can make your inputs "sticky", meaning that what's entered into a field stays there after submission.

    An example would be as follows:

    PHP Code:
    <textarea name="comments">
        <?php if (isset($_POST["comments"])) {echo $comments;} ?>
    </textarea>
    This thread probably should be moved to the PHP forum.


Bookmarks

Posting Permissions

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