| Author |
How to submit struts form based on user confirmation through javascript
|
BabuRajendraPrasad Tavva
Greenhorn
Joined: Jun 30, 2009
Posts: 6
|
|
Hi
I have an application which developed in Struts.
There is one jsp page for modifying a record. When user clicks the submit button, i have to ask confirmation whether he is willing to change the record or not.
If user says 'yes' , i have to submit that jsp so that the corresponding action class is called. Otherwise i should not submit and the control should remain in the same page.
I tried this by calling a javascript function where i am taking user input. Later, the page getting submitted irrespective of the user input.
Below is the javascript code i have written.
function submitForMod(){
alert('inside submitForMod()');
var modForm=document.getElementById("modifyCatalogueForm");
alert(modForm.name);
modForm.action="modifyCatalogue.do";
var confSub=false;
confSub = confirm("Are you sure you want to modify this record?");
alert(confSub);
if(confSub == true){
modForm.submit();
}
}
Even user selects 'Cancel', i.e, false, the page is getting submitted.
Can anybody help me out how to control this and should not happen submit for 'Cancel'?
Thanks in advance.
Best Regards
Babu
|
 |
Roberto Hernandez
Ranch Hand
Joined: Apr 29, 2009
Posts: 33
|
|
I think your problem is that you are calling your function inside a submit button and not a simple button, so the form gets submitted regardless of what the user clicks on.
example: <input type="submit" onclick="submitForMod()" value="submit" />
Easiest solution would be to change your submit button to a "Button" type
If you still want to keep your submit button, then just add an event to your function
Add evt to the javascript function declaration
and add 'evt.preventDefault();' to the else section;
|
 |
BabuRajendraPrasad Tavva
Greenhorn
Joined: Jun 30, 2009
Posts: 6
|
|
Dear Roberto,
Good Morning.
Thanks for your reply with valuable information.
I will try the code changes recommended by you.
I will post my response if i face further any problem.
Have a good day and nice week end.
Once again thanks.
Best Regards
Rajendra
|
 |
 |
|
|
subject: How to submit struts form based on user confirmation through javascript
|
|
|