Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

How can i post data from JSP to Servlet through JavaScript

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    This tiny ad is guaranteed to be gluten free.
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic