Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need assistance adding a CANCEL button next to a SAVE button in a form 1

Status
Not open for further replies.

rleyba828

Technical User
Joined
Sep 29, 2004
Messages
53
Location
US
Hi team,

I'm very new to javascript but I have an urgent requirement to be able to add a "Cancel" button next to a "Save" button on a form I'm building. The form itself is in PHP but the template allows us to insert javascript code there. I have a small snippet below and I just need a way so that next to the "Save" button will be a "Cancel" button where if the user clicks it, it aborts the form data entry and goes back to the previous page, as though the user pressed the "back" button on his/her browser.

Thanks very much for all the help.


Code:
<!--<fieldset><legend></legend>-->
 <table><tr><td> <input name="--session:save" value="Save" type="submit" />

  </td><td>   </td></tr></table>
  <!--</fieldset>--> 
    
      
   
      </div>
<div class="formHelp"></div>
</div>
</td>
</tr> 
</table></div>
</form>
 
The easiest way to implement this is to attach a JavaScript event to a click on the new button that will traverse the history back one notch.

Other methods include maintaining (false) state on the server side or showing the form as a modal dialogue (when the cancel button just dismisses the dialogue).
 
Thanks jpadie.
I was particularly interested in the JavaScript code that would allow me to add the cancel button on the form. Not sure how to set that up.

Thanks.
 
Code:
<button onclick="history.go(-1);">Cancel</button>
 
I'll try this out and post the results. Will let you know how it goes....thanks.
 
Working perfectly, thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top