1

I am displaying some records table where each row contains two buttons like

"Accept" and "Reject"

If I click on "Accept" then the form should be submitted and the button should Replace with "Cancel" button and page should reload with fresh content in the table.

And If I click on "Reject" button then "Accept" button should hide And page should reload with fresh content.

I have tried something but did not work.

$(document).ready(function(){
      $("#upComing").submit(function(){
        alert("Submitted");
      });
      $("#btnAccept").click(function(){
          $("form[value='Accept${upComLeave.employee_id}']").submit();
          location.replace("#btnCancel");

      });  
    });

please help me.

2
  • Hide btnAccept and show btnCancel, using .hide() and .show() Commented Apr 7, 2014 at 9:57
  • I did try but did not work because the form is getting submit and not going further Commented Apr 7, 2014 at 10:00

1 Answer 1

1

You can have three buttons, Accept, Cancel (hidden at first) and Reject and show and hide them to achieve what you describe:

$('#btAccept').click(function(){
    $(this).hide();
    $('#btCancel').show(); 
    //submit form
});

$('#btCancel').click(function(){
    //cancel ajax request
    return false; //prevent form from submitting
});

$('#btReject').click(function(){    
    $('#btAccept').hide(); 
    //refresh content
    return false; //prevent form from submitting
});

Here's a fiddle that shows it working.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried your solution and the button is getting replaced but if I refresh the page then form is submitting twice i.e.duplicate submit
how to restrict that?
@user3448105 if you don't want the button to automatically submit the form you can return false from the handler. I'll update the answer. Also, you might want to check the section "The event handler and its environment" here.
I got your answer.I have been trying on duplicate form submition in spring and jquery however,have not succeed.
I want the button to submit the form But,When we refresh the page then it should not submit twice right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.