I wish to have a confirmation on a delete button, and am attempting to do it all in one line… this is the regular onClick event without the delete confimration:
onClick='this.form.action="/Config?pg=FIBiller&cmd=delete";'
I found online that a confirm delete can be implemented as such:
"return confirm('Are you sure you want to delete?')"
How can I incorporate this into my onClick event so it’s one line, don’t want to use more javascript? If I must do so, than how would I incorporate the action for a “yes” on the message box in the javascript function?
If I understand you correctly, you just want
Or if you really can’t change your form as such for some unclear reason (bad design maybe?), then you need to introduce an
if-elseblock as follows which changes the form’s action on confirmation and returnsfalseon cancel.Note: if you want to add more calls or want to improve readability, introduce braces:
Unrelated to the concrete problem, I’d suggest to get rid of
cmd=deleteas you could also just check that by giving the delete button a name so that it will be sent as request parameter as well:you could then check as follows in the JSP/Servlet side if it’s been pressed:
By the way, deleting by GET is a bad idea. Rather use POST. Otherwise all delete links will be executed when a searchbot comes along your website and crawls all GET links/actions without executing JavaScript. You also don’t want the resulting delete requests to be bookmarkable, right?