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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JS confirm to submit form 1

Status
Not open for further replies.

scapes

Technical User
Feb 27, 2004
4
AU
Hello,

I am trying to find a way to add a 'failsafe' on a <form> button that's used to delete a member of a script I'm workign on.The point being that a user has complained they have several times accidentally deleted a member, and they would like it to "ask them if they are sure" before it actually deleted the member.

The script is PHP, using HTML <form> code inside an echo statement. I thought a Javascript confirm box would be the perfect mechanism, but with my limited JS expertise have had a lot of trouble in the past trying to use JS and PHP together,

The existing code is something like this:

<form action=thispage.php>options=values method=post><input type=hidden name=session_stuff><input type=hidden name=formname value=sent><input type=hidden name=fac value=trash><input type=submit value=\"Delete\"></td></form>

So, given that it's inside a PHP echo statement, could I add an onClick code to it to make the user confirm before continuing? Or would somethign else be best? And either way, how? Would love any input on this.

Many thanks,

Kevin
 
[1] There is a typo of angle bracket after php. I suppose it is a typo.

[2] To add a confirm prompt, like this.
[tt]
<form action=thispage.php[highlight] [/highlight]options=values method=post [blue]onsubmit="confirm('Do you want to submit?')"[/blue]><input type=hidden name=session_stuff><input type=hidden name=formname value=sent><input type=hidden name=fac value=trash><input type=submit value=\"Delete\"></td></form>
[/tt]
You have to make sure quotes are compatible with the unshown quotes of this php line (like how you write the delete value suggest).

[3] Be careful as none of the attributes is quoted. Being quoted is better, but without, it can still be functional as long as there is no space in the attributes' value.
 
Amendment

I forget to put in the return keyword at the last minute before posting. This is how it should be read.
[tt]
<form action=thispage.php options=values method=post onsubmit="[red]return[/red] confirm('Do you want to submit?')"><input type=hidden name=session_stuff><input type=hidden name=formname value=sent><input type=hidden name=fac value=trash><input type=submit value=\"Delete\"></td></form>
[/tt]
 
Many thanks :) Yes the angle bracket was a typo - I thought there would be an easy way to do this - your post was exactly what I was hoping for.

Best regards,
Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top