I have two textfield and dropdown, i want add date to the first textfield and when change dropdown menu add year or month dynamically to the second text-field
and I used this code but it give

function calDate() {
var dateArr = document.getElementById('date_field1').value;
var date1 = new Date();
document.getElementById("date_field2").value = date1.getDate() + "/" + (date1.getMonth()+1) + "/" + date1.getFullYear();

What are the values of dateArr[0], dateArr[1], dateArr[2]?

Also instead of having line 5, why not remove it and add 5 on line 4 (dateArr[0] + 5)

I want to add date at the text field and use dropdown menu when chnage the add month or add year and display it at the second textfield
i used another code

<script language="javascript">

function calDate() {
var d = new Date(document.getElementById('year1').value); 
document.getElementById("year1").value= d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate(); 

  document.getElementById("year2").value= d.getFullYear()+"-"+(d.getMonth()+2)+"-"+d.getDate(); 
		else if	(document.form1.contact_status.value=='share'){
 document.getElementById("year2").value= d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate(); 

I want to add date in this format(y-m-d) when used give me "NaN-NaN-NaN"
how to make it accept ?

What is the value of document.getElementById('year1').value at line 4?
At line 5 what are the values of d.getFullYear(), d.getMonth() and d.getDate()?

Also what is the purpose of line 9, it seems to be doing nothing?

I just realized also, what happens if d.getMonth() returns 12? You are adding 2 to it which would make it 14 and not a valid number for a month.