0

I am working on JSP web page and on an input text where user can select a date on the textbox. I need to retrieve that value and update it on my database by calling a Java method that I created.

So the input looks like below:

End Date:<input class="txtEndDate" type="text" id="txtEndDate" name="txtEndDate" readonly/><br><br>

And my Javascript function as shown:

 // function to save data into table
    function save() {


        var enddate = $('#txtEndDate').val();

        <%

  // function to update the value
         fileFacade.insert_update(id,uniquecode,date,//enddate??);

        %>


    }

Now I know javascript is client side while Java is back end part but I need to pass enddate to the function parameter. Is there any way I could accomplish this?

EDIT:

updateURL.jsp:

<%@ page import="java.sql.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>

<%@ page import="java.util.Locale" %>
<%@include file="../../../WEB-INF/jspf/mcre.jspf" %>
<%@include file="../../../WEB-INF/jspf/session.jspf"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>


</head>
<body>

<%
    long fileID = Long.parseLong(request.getParameter("id"));
    String uniquecode=request.getParameter("uniquecode");
    String startdt=request.getParameter("startdate");
    String enddate=request.getParameter("enddate");







    int enablestatus= Integer.parseInt(request.getParameter("enable"));

    fileFacade.insert_update(fileID,uniquecode,startdt,enddate,enablestatus);



%>

</body>
</html>
4
  • 1
    Take a look at ajax Commented Mar 25, 2019 at 10:03
  • "Java is mainly back end part" - Java is backend only (except you're talking about Applets which I doubt) Commented Mar 25, 2019 at 10:05
  • hope this helps. it is bout how to make ajax calls from java Commented Mar 25, 2019 at 10:23
  • By the way, you might be interested in the Vaadin web app framework. On-the-fly at runtime, Vaadin auto-generates all the HTML, CSS, JavaScript, AJAX, DOM, WebSocket, and Push code needed to render the client-side user-interface (in web browser) of your server-side app written in pure Java. Commented Mar 25, 2019 at 15:28

1 Answer 1

2

You can call ajax method and update you data via API

follow code below:

fuction updateData(id, uniquecode) {
  var enddate = $('#txtEndDate').val();
  var radioEnableStatus = = $("input[name='radioEnableStatus']:checked").val();
  $.ajax({

    url : 'API URL',
    type : 'POST',
    data : {
        'id' : id,
        'uniquecode': uniquecode,
        'enddate': enddate,
        'radioEnableStatus': radioEnableStatus
    },
    dataType:'json',
    success : function(data) {              
        alert('Data: '+data);
    },
    error : function(request,error)
    {
        alert("Request: "+JSON.stringify(request));
    }
  });
}
Sign up to request clarification or add additional context in comments.

2 Comments

Comments are not for extended discussion; this conversation has been moved to chat.
i'm in chatbox now

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.