SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP on reset button to clear html/PHP form.

    How do I use a button to reset a form.
    Just like the submit button, I have a reset button but when I click it the form does not clear.

    I am actually using an image for the button, like this.

    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" />

    The form is process with a PHP script but the reset does not work

    Any help will be greatly appreciated.

    IC

  2. #2
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" />
    try this

    HTML Code:
    <input name="reset" type="reset" src="images/reset_button.jpg" class="reset_button" />

  3. #3
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deepson2 View Post
    HTML Code:
    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" />
    try this

    HTML Code:
    <input name="reset" type="reset" src="images/reset_button.jpg" class="reset_button" />
    Thanks very much for the time and efforts, however, it did not work, when I enter the code or did as you indicated, the image is replace with an html default button.

    So now how do you do this without losing the image. By changing the type to image, it removes the image and replaces it with a html button.

    Another other ideas.

    IC

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Generally there is no way of doing that with reset button as far as i know. But you should write some css or some javascript function to trigger when the normal image/link is clicked which clears all the fields of the form.

    See this:
    http://www.cs.tut.fi/~jkorpela/forms/imagereset.html
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this

    HTML Code:
    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" onclick="document.theForm.reset();return false;" />
    or you can check this link

    http://www.htmlcodetutorial.com/form...msupp_142.html

  6. #6
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    I'd recommend using a checkbox instead of a button. A button must be in down state for PHP to receive it's value when it's clicked - typically this is only going to occur for the submit button - unless you want the form immediately submitted when the reset button is hit.

  7. #7
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deepson2 View Post
    Try this

    HTML Code:
    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" onclick="document.theForm.reset();return false;" />
    or you can check this link

    http://www.htmlcodetutorial.com/form...msupp_142.html
    Simply reset(); is sufficient.

    HTML Code:
    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" onclick="reset();" />
    The reason is the form to be reset is already in the scope of the button they're interacting with. You don't need to restate the path if you don't want (tightens the code and lessens the chance of error though).

  8. #8
    SitePoint Addict
    Join Date
    Aug 2008
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    Simply reset(); is sufficient.

    HTML Code:
    <input name="reset" type="image" src="images/reset_button.jpg" class="reset_button" onclick="reset();" />
    The reason is the form to be reset is already in the scope of the button they're interacting with. You don't need to restate the path if you don't want (tightens the code and lessens the chance of error though).
    Well I applied this but it does not work.

    The PHP form I have is a quote form, so nothing is actually being submitted to a database or e-mail address.

    You put in information, click submit and get a quote.

    The form clears fine if you select information and then click the reset button
    But when you submit the information, you get a quote but the form does not clear - this is why I use the reset button to clear or reset the form.

    But the form does not reset or clear after you have submit it.

    IC


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
  •