How to prevent jquery datepicker from clearing date on submit in jsp

125
November 14, 2021, at 8:50 PM

I want to prevent my date from clearing when I hit the search button. I have tried setting form onSubmit to return false still same issue is happening.

<html:form styleClass="form-horizontal" action="refund"
                            method="post" onsubmit="return false">
    <html:hidden property="actionType" />
    <html:hidden property="fromDate" />
    <html:hidden property="toDate" />
    <div class="form-group">
        <label class="control-label"> From Date: </label> <br>
    </div>
        <div class="input-group date form_date" data-date=""
            data-date-format="yyyy-mm-dd">
            <!--mm/dd/yyyy-->
            <input class="form-control border-radius-input"
                onkeypress="return Date1(event);" maxlength="10"
                id="fdate" type="text" placeholder="yyyy-mm-dd"> <span
                class="input-group-addon"><span
                class="glyphicon glyphicon-calendar"></span></span>
        </div>
        <input type="hidden" id="dtp_input2" value="" />
    <div class="form-group">
        <label class="control-label"> To Date: </label> <br>
    </div>
    <div class="col-lg-12">
        <div class="input-group date form_date" data-date=""
            data-date-format="yyyy-mm-dd">
            <!--mm/dd/yyyy-->
            <input class="form-control border-radius-input"
                onkeypress="return Date1(event);" maxlength="10"
                id="tdate" type="text" placeholder="yyyy-mm-dd"> <span
                class="input-group-addon"><span
                class="glyphicon glyphicon-calendar"></span></span>
        </div>
        <input type="hidden" id="dtp_input2" value="" />
    </div>
    <div class="btn-div" style="text-align: center;">
    <button class="btn btn-primary btn-o mr-2" onclick="search()">
    Search</button>
    <input class="clr-btn" type="reset" value="Clear" onclick="clearFields()">
    </div>
</html:form>

and my search function is as below

function search() {
            document.forms[2].fromDate.value = $('#fdate').val();
            document.forms[2].toDate.value = $('#tdate').val();
            document.forms[2].actionType.value = "search";
            document.forms[2].submit();
        }

My declaration for the datepicker is given below

$('.form_date').datetimepicker({
            weekStart : 1,
            todayBtn : 1,
            autoclose : 1,
            todayHighlight : 1,
            startView : 2,
            minView : 2,
            forceParse : 1
        });

Please ignore my div closing syntax as while posting this question I messed up with div closing but html is working fine no issue with it.

READ ALSO
My button doesn&#39;t go to the right side of my nav [closed]

My button doesn't go to the right side of my nav [closed]

Want to improve this question? Add details and clarify the problem by editing this post

57
Can&#39;t load random images

Can't load random images

I've been trying to get the cat images displayed in random order from the top arrayMy click4pics doesn't work with the code that is shown, I get a message that the images cannot be found however when I change the image source to load only one image the function...

77
Google Cloud Vision Text Detection - Ignore Text on Logos

Google Cloud Vision Text Detection - Ignore Text on Logos

I'm using the following code to detect text on an image and then get that result as a string array:

64
Android ContentProvider receiving end: Threading necessity or not?

Android ContentProvider receiving end: Threading necessity or not?

When I extend ContentProvider and implement the call() API:

68