Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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
     
    I promise I will be the best, most loyal friend ever! All for this tiny ad:
    Two software engineers solve most of the world's problems in one K&R sized book
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic