• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • 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

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.

    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.

    Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
    Devious Experiments for a Truly Passive Greenhouse!
      Bookmark Topic Watch Topic
    • New Topic