Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  110] [ 4]  / answers: 1 / hits: 15500  / 15 Years ago, wed, november 18, 2009, 12:00:00

Let's say I have this form and script:



<SCRIPT LANGUAGE=JavaScript>
function handleSubmit() {
return false;
}
function Delete(element) {
var is_confirmed = confirm(Delete this record? n + title + + date);
if (is_confirmed) {
document.getElementById(Novinky).submit();
}
}
</SCRIPT>

<form action=index.php method=post id=Novinky onsubmit=return handleSubmit();>
<input onclick=Delete(this) value=Smazat name=delete[12] type=submit />
</form>


Is there a way to get the submit button data (delete[] -> Smazat) to the POST request?


More From » post

 Answers
15

It seems that you are submitting a different form than the one that contains the Delete button (id=Novinky). In this case you could add a hidden field in this form and set it's value to the value of the Delete button just before submitting it:



if (is_confirmed) {                     
document.getElementById('myhiddenfield').value = element.value;
document.getElementById('Novinky').submit();
}





UPDATE:



Instead of attaching a click handler to the delete button you could do this:



<script type=text/javascript>
function handleSubmit() {
return confirm('Delete this record?');
}
</script>

<form action=index.php method=post id=Novinky onsubmit=return handleSubmit();>
<input value=Smazat name=delete[12] type=submit />
</form>


This will automatically post the value of the Delete button when you submit it.






UPDATE2:



<script type=text/javascript>
function handleSubmit() {
// check which button was clicked:
alert(window.clicked);
return confirm('Delete this record?');
}
</script>

<form action=index.php method=post id=Novinky onsubmit=return handleSubmit();>
<input onclick=window.clicked=this.value; value=Smazat name=delete[12] type=submit />
</form>

[#98288] Saturday, November 14, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;