This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

How can i post data from JSP to Servlet through JavaScript

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've below jsp.



Here I've 2 questions,
  • I'm unable to submit my data to database using a button through JavaScript. Using a submit type is good, but here i need to fill a textbox(id = endTime) with date and time when i hit submit. That's why I've used it as a button instead of submit. I thought that the button is not working, but when ever i click on that button the latest time is fetched into textbox(id = endTime).
  • I need a small pause of say 2-3 seconds after the time is generated in the textbox and then the post should be done.


  • Please let me know how can i get this and where am i going wrong.

    Thanks.
     
    Rakesh Keerthi
    Ranch Hand
    Posts: 153
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi All,

    If anyone have such problem, I've found a solution that worked for me.

    use an id for the form like



    Then for the button add an onClick event as below

    <input type="button" value="Submit Form" onclick="getLastDate()" />

    and in the javascript in <head>, use the below method. Make sure that the method name is same as the onClick event attribute value.

    Here i need to fill a text box with current time, so i used the below code, you have to change as per your requirement.



    This is solution for my first question.

    For time delay i.e. my second question.

    Use a setTimeout method in javascript as below. Here 3000 means 3 seconds.



    This has to be given wherever you want a time delay,

    In my case, i need to get the time in text box, pause it and then submit the form data, so i took this after the time is fetched (please refer to my third code block for full js method).

    This is how I've solved my problem.

    Cheers,
    Rakesh
     
    Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!