| | |
Problems with form submition
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Hi there
I have a form that I'm trying to submit but it just doesn't want to play nice.
The form i have has 2 submit buttons. One processes php code that updates info in a DB and the other deletes the info in the DB. The problem is that I have a popup asking for confirmation on the deleting and when I click ok nothing happens. All I need to know is how to submit my form using javascript so that it processes the PHP code to delete the DB entry.
form tag and delete button
confirmation popup
Code that deletes DB entry
I have a form that I'm trying to submit but it just doesn't want to play nice.
The form i have has 2 submit buttons. One processes php code that updates info in a DB and the other deletes the info in the DB. The problem is that I have a popup asking for confirmation on the deleting and when I click ok nothing happens. All I need to know is how to submit my form using javascript so that it processes the PHP code to delete the DB entry.
form tag and delete button
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<form name="formname" id="formname" method="post" action="<?= $_SERVER['PHP_SELF']?>" onSubmit="return checkWholeForm(this);"> <input onclick=\"confDelete()\" type="submit" name="delete" value="Delete">
confirmation popup
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- function confDelete() { var answer = confirm("Msg") if (answer==true){ document.formname.submit(); return true; } } //--> </script>
Code that deletes DB entry
php Syntax (Toggle Plain Text)
if (isset($_POST['formname'])){ \\ code goes here }
This user has a spatula. We don't know why, but we are afraid.
Hi,
you cant have two submit button on one form, do one thing:
have two simple button< input type="button" value="delete"......> and have on hidden field in form with name "task".On onclick event of these button call a function where you set the value of task="delete" or whatever you want, after this submit the form using javascript.
On server side check the value of task, according to value you take the action( either delete or add or....), one more thing in all cases you'll be having only one php page, where you will perform action according to "task" value.
Have a nice time !!!
you cant have two submit button on one form, do one thing:
have two simple button< input type="button" value="delete"......> and have on hidden field in form with name "task".On onclick event of these button call a function where you set the value of task="delete" or whatever you want, after this submit the form using javascript.
On server side check the value of task, according to value you take the action( either delete or add or....), one more thing in all cases you'll be having only one php page, where you will perform action according to "task" value.
Have a nice time !!!
Last edited by DangerDev; Apr 3rd, 2008 at 11:57 am.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
DangerDev, My problem is that I don't know javascript very well and haven't been able to find any solutions. Is the section of code for submitting the form correct?
P.S. You can have two submit buttons on one form. I've used it successfully on many pages.
javascript Syntax (Toggle Plain Text)
document.formname.submit();
P.S. You can have two submit buttons on one form. I've used it successfully on many pages.
This user has a spatula. We don't know why, but we are afraid.
You can actually have 2 submit buttons in a form. Eg. But, since both the buttons are submit buttons, onSubmit event will be fired when you click either of the buttons.
php Syntax (Toggle Plain Text)
<?php if($_POST['submit1']) { echo "Submit1 pressed! Add/update the records"; } if($_POST['submit2']){ echo "Submit2 was pressed ! Now delete the records !"; } ?> <html> <head> <script type='text/javascript'> function confirmdel() { var val = confirm("Do you really want to delete ?"); if(val) { return true; } else { return false; } } function calltest() { alert("Hi there!"); return true; } </script> </head> <body> <form method="post" action="thispage.php" onsubmit="javascript: return calltest();"> <input type="submit" name="submit1" value="add"><input type="submit" name="submit2" value="delete" onclick="javascript: return confirmdel();"> </form> </body> </html>
Last edited by nav33n; Apr 3rd, 2008 at 12:13 pm.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
yes it is correct, but when you are submitting how you are making difference at server side(of which button user has clicked), if you have problem in that see my suggested solution....
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
•
•
•
•
DangerDev, My problem is that I don't know javascript very well and haven't been able to find any solutions. Is the section of code for submitting the form correct?javascript Syntax (Toggle Plain Text)
document.formname.submit();
P.S. You can have two submit buttons on one form. I've used it successfully on many pages.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
•
•
I have called it submit1 and submit2.
then there is no problem at all, you can check at server side the name of button and on the base of this you can have intended functionality.....
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
![]() |
Similar Threads
- IE7 sucks!!!! (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Need help in javascript and modal window
- Next Thread: form working in IE not Firefox -why?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box bug calendar captchaformproblem cart checkbox child class codes column cookies createrange() css cursor decimal design disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox focus forms frameworks google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem progressbar prototype redirect regex runtime scale scroll search select session shopping size sql text textarea toggle w3c web website window windowofwords windowsxp wysiwyg \n






