I'm still a learner on PHP.
I have a button, and it shall run a JavaScript after clicking it, but I want it to show an alert / pop up for users to confirm whether to continue or to abort.
Can I do the function in my PHP file in the button code?
<TD style='text-align:left;padding:0;margin:0;'>
<INPUT type='button' onmouseup="javascript:JS1();" value='JS1'></INPUT>
</TD>
you need to make function and use confirm();
<TD style='text-align:left;padding:0;margin:0;'>
<INPUT type='button' onmouseup="myFunction();" value='JS1'></INPUT>
</TD>
And
<script>
function myFunction() {
confirm("Please confrim");
}
</script>
Have you tried bootstrap modal?
https://www.w3schools.com/bootstrap/bootstrap_modal.asp
https://getbootstrap.com/docs/4.0/components/modal/
https://getbootstrap.com/docs/3.3/javascript/
I have provided 3 links. I think these might help you a little. Do a research and it won't be very hard. Good luck.
Writing code is not what is supposed here.
But, still following pseudo code and concepts should work.
Steps:
onclick
attribute.onclick
function, add a confirmation
popup.confirm()
returns true
if user selects yes
, or else it will return false
.Now, you have to proceed only if true
is returned by confirm()
.
And javascript code:
<script>
function JS1() {
if (confirm('Your confirmation message')) {
// Write your code of form submit/button click handler.
}
else {
return false;
}
}
</script>