Call cancel button from ajax(JS)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Call cancel button from ajax(JS)

    I'm using ajax in my php site. In there I have two buttons named as submit and cancel. When I click submit button it validates data using ajax. (No need to use form for this). But the following code is not working for cancel button
    Code:
    function Cancel(){
    cancel = document.getElementById('test').value.reset();
    }
    If I put form,
    Code:
    (<form name"test.php">)
    cancel button is working but errors return from the submit button are gone. Could someone pls help me ?
    Last edited by Dormilich; Jun 30 '09, 07:07 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by ghjk
    But the following code is not working for cancel button
    Code:
    function Cancel(){
    cancel = document.getElementById('test').value.reset();
    }
    first, there is no native reset() method to the String object (doing a reset I'd rather define element.value = "";)

    second, sumbit/reset buttons are supposed to be used in forms (mind that you can have multiple forms and a submit/reset button works only on the form, where it is defined). you should rather use the normal click buttons if you don't have a <form> element*.


    * - semantically it doesn't make sense to have a submit button without the corresponding form (i.e. without something to submit)

    Comment

    Working...