javascript - How to set date and month in input type month from text field -


i have 3 input fields:

<input type="month" id="incidentdate" name="incidentdate" class="incidentdate" /> <h:inputtext id="incidentmonth" styleclass="incidentmonth" value="#{incidents.month}" /> <h:inputtext id="incidentyear" styleclass="incidentyear" value="#{incidents.year}" /> 

i trying convert input type text value date format not working.

i doing in jquery , want in page onload getting data form backend on load

var newdate = $(".incidentmonth").val() + "-" + $(".incidentyear").val(); var converdate = new date(newdate); $("#incidentdate").val(converdate); 

for more info getting value in "incidentyear" 2011 , in month incidentmonth 12 jsut year , month

http://jsfiddle.net/x3j199yd/5/

what understand question that, want set month , year in input type "month". here code

var userinput= $("#incidentmonth").val() + "-" + $("#incidentyear").val(); var dataobj= new date(userinput); var mynewdate=dataobj.getfullyear().tostring() +'-'+ (parseint(dataobj.getmonth())+1).tostring() mynewdate= mynewdate.split('-')[1].length<2? mynewdate.split('-')[0]+'-0'+mynewdate.split('-')[1]:mynewdate.split('-')[0]+'-'+mynewdate.split('-')[1] document.getelementbyid("incidentdate").value = mynewdate; 

fiddle


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -