N
N
Nikolay Baranenko2016-07-25 17:18:00
JavaScript
Nikolay Baranenko, 2016-07-25 17:18:00

How to do something in JS by pressing a button on the form and then start the servlet?

Hello.

There was a need to do something in JS by pressing a button on the form and then start the servlet.

How is it possible to do this?

ps

tried

document.location.href="${pageContext.request.contextPath}/NewServlet";


But a 405 error occurs

HTTP Status 405 - HTTP method GET is not supported by this URL
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Baranenko, 2016-09-02
@drno-reg

managed to solve it

<form method="POST" action="InsertInDB" name="InsertInDB">
элементы формы table, input и т.д.
<button class="btn btn-infoy" type="submit" onclick="GetDefValue()"><i class="glyphicon glyphicon-inbox"></i> Сохранить</button>
</form>

<script>
    function GetDefValue () {
        var elem = document.getElementById("email1");
        var defValue = elem.defaultValue;
        var currvalue = elem.value;
        if (defValue == currvalue) {
            document.getElementById("demo_3").innerHTML = "Знечение не изменилось";
        } else {
            document.getElementById("demo_3").innerHTML = "Значение изменилось с " + defValue +
                    "\n  на " + currvalue;
        }
    }
</script>

the script logic is also executed and the result is sent to the servlet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question