简体   繁体   中英

jQuery set defaul value of date picker input

I am building a web app that uses a date picker to filter the search results of some event items.

The form submits via ajax just fine, (I am getting results) but I am having issues with setting a default value into the datepicker. The input type is text based, but it functions like a javascript DatePicker. Thanks for any help.

Note: I did not build the form from scratch, but it is customized to do what I need it to.

jQuery:

// Get current date
var date = new Date();

var month = date.getMonth()+1;
var day = date.getDate();
var year = date.getFullYear();

var currentDate = day + "-" + month + "-" + year;

$("#CAT_Custom_2_Min").val(currentDate)
$("#calendar-form").submit();

Form HTML:

<form id="calendar-form" action="/Default.aspx?CCID=17654&amp;FID=197248&amp;ExcludeBoolFalse=True&amp;PageID=11940414" method="post" name="catcustomcontentform95560">
    <table cellspacing="0" cellpadding="2" border="0" class="webform">
        <tbody>
            <tr>
                <td><label>Event Start Time Min/Max:</label><br />
                <input type="text" onfocus="displayDatePicker('CAT_Custom_2_Min');return false;" style="background-color: #f0f0f0;" readonly="readonly" class="cat_textbox" id="CAT_Custom_2_Min" name="CAT_Custom_2_Min" /> 
                And <input type="text" onfocus="displayDatePicker('CAT_Custom_2_Max');return false;" style="background-color: #f0f0f0;" readonly="readonly" class="cat_textbox" id="CAT_Custom_2_Max" name="CAT_Custom_2_Max" /></td>
            </tr>
            <tr>
                <td><input type="submit" value="Search" class="cat_button" /></td>
            </tr>
        </tbody>
    </table>
</form>

Live Page: http://sevenclanscasino.designangler.com/warroad/warroad-calendar

jsfiddle: http://jsfiddle.net/VJQYb/

// Get current date
var date = new Date();

var month = date.getMonth()+1;
var day = date.getDate();

var currentDate = date.getFullYear() + '/' +
  (month<10 ? '0' : '') + month + '/' +
  (day<10 ? '0' : '') + day;

// Date for 7 days from current date 
var futureDate = new Date();
futureDate.setDate(date.getDate() + week);
$("#CAT_Custom_2_Min").val(currentDate);
$("#CAT_Custom_2_Max").val(futureDate);
$("#calendar-form").submit();

I removed the variable d as it wasn't being declared, and added a # in front of CAT_Custom_2_Min and CAT_Custom_2_Max

you can try

<input type="text" id="date1" />

<script type="text/javascript">
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var cdate = month + "/" + day + "/" + year;
document.getElementById("date1").value=cdate;
</script>

just an example to clear the idea of showing date in input box...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM