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
It'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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.