How to display the date field in input box after submitting the form in javascript?

49
February 17, 2021, at 05:30 AM

I need to display the user-selected date in the input box on the same page once the form gets submitted. I was referring this link and if I try to implement the same in my code, my form is not getting submitted and am not able to see the desired output.

Here is my code:

HTML:

<form method="POST" id="myform">
<div class="de-section de-cart-stat d-flex align-items-center flex-wrap mt-4">
StartDate:<input type="date" id="stdate" name="stname">
EndDate:<input type="date" id="eddate" name="edname">
<button id="submitbtn" type="submit">Submit</button>

JS:

$("#submitbtn").click(function() {
 if ($("#stdate").val().length === 0 || $("#eddate").val().length === 0) {
   $("#errorModal").modal("show");
   return false;
  }
  else{
     $("form").submit();
}
});

Any ideas to display the dates in the input box after clicking the submit button using javascript.?

Answer 1

If you want your cake and eat it too, use AJAX

$("#myform").on("click", function(e) {
  e.preventDefault(); // stop submission 
  if ($("#stdate").val().length === 0 || $("#eddate").val().length === 0) {
    $("#errorModal").modal("show");
    return;
  }
  $.post("someUrl",$(this).serialize(),function(res) {
    $("someContainer").html(res)
  });  
});
READ ALSO
BMI Calculator program with Tkinter()

BMI Calculator program with Tkinter()

I want to create a BMI calculator program with Tkinter but I'm stuck at calculation procedure I use StringVar() to keep user data to calculate but I don't know how to calculate

54
Multi level product flavors in buildVariant in Android

Multi level product flavors in buildVariant in Android

Our app has default buildtypes and productflavors as

75
Can someone help me spot my error, I can&#39;t find it and it won&#39;t render [closed]

Can someone help me spot my error, I can't find it and it won't render [closed]

Want to improve this question? Update the question so it's on-topic for Stack Overflow

55
Woocommerce Api: Store Category with image get error Bad Request 400

Woocommerce Api: Store Category with image get error Bad Request 400

I am using Laravel 8 with woocommerce api'sI am creatng Product Category using Woocomerce api's documentation

70