i want value of 3 drop down boxes displayed somewhere else when button clicked.
i googled lot , found post used day.options[day.selectedindex].value; , worked when tried managed pick trying read values (which further had gotten before tried method) return day:day month:month year:year opposed actual values of each. im assuming problem comes in because of loops within drop down boxes have no idea how fix it.
function age(gender){ if (gender!==undefined){ el1 = document.getelementbyid('userdata'); el1.innerhtml += gender +"<br>"; } el1 = document.getelementbyid('farespage'); var month = 1; var day = 1; var year = 2002; var newhtml = ""; newhtml +="<div id=\"ageheading\">date of birth</div><div id=\"agebox\"><div class=\"innerage\" onclick=\"relationship('"+day+"')\">day<select id=\"dropdownday\">"; for(var day; day<=31; day++){ newhtml +="<option value=\"day\">"+day+"</option>"}; newhtml +="</select></div><div class=\"innerage\">month<select id=\"dropdownmonth\">"; for(var month; month<=12; month++){ newhtml +="<option value=\"month\">"+month+"</option>"}; newhtml +="</select></div><div class=\"innerage\">year<select id=\"dropdownyear\">"; for(var year; year>=1920; year--){ newhtml +="<option value=\"year\">"+year+"</option>"}; newhtml +="</select></div><button type=\"button\" onclick=\"goback('gender')\">back</button><button type=\"button\" onclick=\"dob()\">enter</button></div>"; el1.innerhtml += newhtml; } function dob(){ var day = document.getelementbyid("dropdownday"); var dayoptions = day.options[day.selectedindex].value; var month = document.getelementbyid("dropdownmonth"); var monthoptions = month.options[month.selectedindex].value; var year = document.getelementbyid("dropdownyear"); var yearoptions = year.options[year.selectedindex].value; var birthday = '<div>day: ' + dayoptions + '</div>' + '<div>month: ' + monthoptions + '</div>' + '<div>year: ' + yearoptions + '</div>'; el1 = document.getelementbyid("userdata"); el1.innerhtml += birthday; window['relationship'](); }
you need make slight fix in age function:
function age(gender){ if (gender!==undefined){ el1 = document.getelementbyid('userdata'); el1.innerhtml += gender +"<br>"; } el1 = document.getelementbyid('farespage'); var month = 1; var day = 1; var year = 2002; var newhtml = ""; newhtml +="<div id=\"ageheading\">date of birth</div><div id=\"agebox\"><div class=\"innerage\" onclick=\"relationship('"+day+"')\">day<select id=\"dropdownday\">"; for(var day; day<=31; day++){ newhtml +="<option value=\""+day+"\">"+day+"</option>"}; newhtml +="</select></div><div class=\"innerage\">month<select id=\"dropdownmonth\">"; for(var month; month<=12; month++){ newhtml +="<option value=\""+month+"\">"+month+"</option>"}; newhtml +="</select></div><div class=\"innerage\">year<select id=\"dropdownyear\">"; for(var year; year>=1920; year--){ newhtml +="<option value=\""+year+"\">"+year+"</option>"}; newhtml +="</select></div><button type=\"button\" onclick=\"goback('gender')\">back</button><button type=\"button\" onclick=\"dob()\">enter</button></div>"; el1.innerhtml += newhtml; }
basically replace value=\"day\">" with: value=\""+day+"\">" , same year , month.