Results 1 to 5 of 5

Thread: send forms

  1. #1
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default send forms

    I've created a simple form:

    PHP Code:
    <form>
    <
    input type="text" id="teken" name="teken" value="" />
    <
    br /><br />
    <
    input type="button" value="send" onclick="check()" />
    </
    form
    I don't use the submit button in order to use a js function, that works on the current page.

    However, it's pretty annoying, after I write in the input text, and I press ENTER (on the keyboard) it doesn't send me the form..

    What can I do?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Replace the button with a regular submit input:
    <input type="submit" value="send" />

    And change your form tag to use the onsubmit event:
    <form action="next.page.url" method="post_OR_get" onsubmit="check();">

    Note that without specifying method and action in your form, your form isn't designed to do anything. Also be aware that javascript is optional and users can avoid it if they try or if they don't have javascript enabled. It will work most of the time, but it's not guaranteed or "secure".
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    d-machine (01-21-2011)

  4. #3
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    I made it cause I don't won't to load a new page after sending the form,
    I want to stay on the same page (without loading it again...).

    How can I do it?

    I want that everytime when you press ENTER it will run the check function.
    I've tried to use: keypress event but I don't know how to apply it.
    Last edited by d-machine; 01-21-2011 at 08:22 AM.

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Use the code I showed you above. If you want to block the page from reloading you can add return false; like this:
    <form action="next.page.url" method="post_OR_get" onsubmit="check(); return false;">

    That will NOT submit the form. However, it will execute the check() function and that can submit the form if needed.


    Again, Javascript is unreliable, so if JS is disabled the form will submit when you press enter. There's no way to stop that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. The Following User Says Thank You to djr33 For This Useful Post:

    d-machine (01-21-2011)

  7. #5
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default

    Thank you very very much !!

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
  •