I would like to add a delete confirmation to my form button Possible javascript to use??
<script type="text/javascript">
function confirmDelete() {
return confirm("Are you sure you want to delete?");
}
</script>
This is currently working inside my form.
<input type="button" onclick="parent.location='<?php echo "delete.php?id=" . $people['id'] ?>'" value='Delete'>
How can I integrate the javascript into the onclick event? Either using the above javascript or any other way that may be better
I would like to add a delete confirmation to my form button Possible javascript to use??
<script type="text/javascript">
function confirmDelete() {
return confirm("Are you sure you want to delete?");
}
</script>
This is currently working inside my form.
<input type="button" onclick="parent.location='<?php echo "delete.php?id=" . $people['id'] ?>'" value='Delete'>
How can I integrate the javascript into the onclick event? Either using the above javascript or any other way that may be better
Share Improve this question edited Jul 24, 2012 at 20:19 Pshemo 124k25 gold badges191 silver badges275 bronze badges asked Jul 24, 2012 at 20:16 user1548769user1548769 3193 gold badges5 silver badges12 bronze badges 1- similar: stackoverflow.com/questions/9139075/… – Ciro Santilli OurBigBook.com Commented May 10, 2016 at 9:21
7 Answers
Reset to default 9It's possible :)
On the tag, use the attribute onsubmit like this :
<form onsubmit="return confirm('Are you sure?');">
or using a method
<form onsubmit="return myMethod">
The same for a button on onclick event. If it return false, it will be not clicked.
Remember, if the method return false, the form will not be submited
How can I integrate the javascript into the onclick event?
<input type="button" onclick="javascript:confirmDelete();" value='Delete'>
and
<script type="text/javascript">
function confirmDelete() {
var status = confirm("Are you sure you want to delete?");
if(status)
{
parent.location.replace("parent.location='<?php echo "delete.php?id=" . $people['id'] ?>'");
}
}
</script>
I hppe this will help you
It work for me
<a href="index.php?action=del&id=125" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
First of all add an onclick method in your HTML, like:
**HTML:**
<a class="btn btn-danger" href="some url" onclick="DeleteItem();"></a>
**JavaScript:**
function DeleteItem()
{
return confirm("Are you sure to delete this")
}
// Or you can simply do it like below:
<button onclick="javascript: return confirm('Are you sure to delete?');">Delete</button>
Bind your event handler in javascript.
<input type="button" id="delete" value='Delete' />
document.getElementById('delete').onclick = function () {
if (confirm('Are you sure?')) {
parent.location='<?php echo "delete.php?id=" . $people['id'] ?>';
}
};
Add button element with onclick event handler as below:
<input type="submit" name="delete" value="Delete" onclick="return confirmDelete();">
and the JavaScript content as below:
function confirmDelete() {
return confirm("Are you sure you want to delete?");
}
It works for me.
HTML also supports a reset button on the form, if you are not attached to using javaScript. You can have a structure like this:
<form>
...
items in your form
...
<input type="reset">
...
</form>
When the reset button is clicked, all of the form inputs will reset to their default values.