dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Form with only one input field!

  1. #1
    Join Date
    Jul 2010
    Posts
    71

    Form with only one input field!

    Hi

    I have made a variety of forms, but I just made one with only one input field type="text". The mysterious case is that when I press enter, the page reloads and places the values in the url!!

    Why does it do that, and how do I prevent it???

    If I make one more text field it doesn't happens!!

    HTML Code:
    <html>
    <body>
    <form name="testform">
    	<input type="text" name="testinput">
    </form>
    </body>
    </html>
    (The form action is not defined because I use ajax to handle the form)

  2. #2
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    What are you trying to do with your form? It needs a method and action attribute to know what to do when it is submitted. Since you haven't provided either, it is using the GET method and the default action is to reload the page. That's why you're seeing this behavior.

  3. #3
    Join Date
    Jul 2010
    Posts
    71
    Hi Big O

    Thanks for the reply!

    I use JavaScript to handle the form with a onchange action. That's why I haven't placed a action inside the form tag!

    I understand that it by default uses GET method, and that it reloads the page, but why doesn't it happen if there are more then one text field?

  4. #4
    Join Date
    Jul 2010
    Posts
    71
    Well the quick solution is to place this inside the <form> tag:

    onsubmit="return false"

    Maybe not pretty but it works!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles