Connecting Tech Pros Worldwide Forums | Help | Site Map

Call cancel button from ajax(JS)

Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#1: Jun 30 '09
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
Expand|Select|Wrap|Line Numbers
  1. function Cancel(){
  2. cancel = document.getElementById('test').value.reset();
  3. }
If I put form,
Expand|Select|Wrap|Line Numbers
  1. (<form name"test.php">)
cancel button is working but errors return from the submit button are gone. Could someone pls help me ?

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#2: Jun 30 '09

re: Call cancel button from ajax(JS)


Quote:

Originally Posted by ghjk View Post

But the following code is not working for cancel button

Expand|Select|Wrap|Line Numbers
  1. function Cancel(){
  2. cancel = document.getElementById('test').value.reset();
  3. }

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)
Reply