I have working struts1 dispatch action and a form having two submit buttons which have parameter and value which calls method name with value. Well there is no problem.

But when clicking on delete button, I want to confirm with bootstrap dialog.

$('.btnDelete').on('click', function(e){
        var $form=$(this).closest('form');
        e.preventDefault();
        $('#confirm').modal({ backdrop: 'static', keyboard: false })
        .one('click', '#delete', function (e) {
            var sectorId = $(this).parent().parent().children()[0].innerHTML;
            var input = document.createElement("input");
            input.setAttribute("type", "hidden");
            input.setAttribute("name", "sectorId");
            input.setAttribute("value", sectorId);
            document.getElementById("sectorForm").appendChild(input);
            $("#sectorForm").submit();
        });
    });

Here e.preventDefault() is needed to stop form submitting. And when a delete button is clicked from dialog a hidden parameter will be passed and form will submit. But sever shows below error message.

HTTP Status 500 - Request[/SectorManagement] does not contain handler parameter named 'action'. This may be caused by whitespace in the label text.

Please note that there is no problem when removing bootstrap dialog.

The solution was to add one more add hidden parameter named action and value.

$('.btnDelete').on('click', function(e){
    var $form=$(this).closest('form');
    e.preventDefault();
    $('#confirm').modal({ backdrop: 'static', keyboard: false })
    .one('click', '#delete', function (e) {
        var sectorId = $(this).parent().parent().children()[0].innerHTML;
        var input = document.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "sectorId");
        input.setAttribute("value", sectorId);
        document.getElementById("sectorForm").appendChild(input);

        input = document.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "action");
        input.setAttribute("value", delete);
        document.getElementById("sectorForm").appendChild(input);
        $("#sectorForm").submit();
    });
});

I don't know but there can be better solution. Will wait for your answers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.