Note that there are some explanatory texts on larger screens.

plurals
  1. POIf you generate a drop down list with javascript can you still post it in a form
    text
    copied!<p>I have generated a drop down list in javascript for my form. however when i post the form the the values of the drop down list are null. Even if i select another option from the list, which means it cant be default. Here is my PHP:</p> <pre><code> $BirthDays = ($_POST['Days']); $BirthMonths = ($_POST['Months']); $BirthYears = ($_POST['Years']); </code></pre> <p>And this is the javascript:</p> <pre><code> function runcalender() { var calendar = [ ["January", 31], ["February", 28], ["March", 31], ["April", 30], ["May", 31], ["June", 30], ["July", 31], ["August", 31], ["September", 30], ["October", 31], ["November", 30], ["December", 31] ], cont = document.getElementById('calender'); //set variables for calender var sel_year = document.createElement('select'), sel_month = document.createElement('select'), sel_day = document.createElement('select'); sel_year.setAttribute("id", "Years"); sel_month.setAttribute("id", "Months"); sel_day.setAttribute("id", "Days"); sel_year.setAttribute("name", "Years"); sel_month.setAttribute("name", "Months"); sel_day.setAttribute("name", "Days"); function createOption(txt, val) { var option = document.createElement('option'); option.value = val; option.appendChild(document.createTextNode(txt)); return option; } function clearChildren(ele) { while (ele.hasChildNodes()) { ele.removeChild(ele.lastChild); } } function recalculateDays() { var month_index = sel_month.value, df = document.createDocumentFragment(); for (var i = 0, l = calendar[month_index][1]; i &lt; l; i++) { df.appendChild(createOption(i + 1, i)); } clearChildren(sel_day); sel_day.appendChild(df); } function generateMonths() { var df = document.createDocumentFragment(); calendar.forEach(function(info, i) { df.appendChild(createOption(info[0], i)); }); clearChildren(sel_month); sel_month.appendChild(df); } function generateYears(){ var dateForYear = new Date(); var x = dateForYear.getFullYear(); var y = x - 100; var df = document.createDocumentFragment(); for (i = x; i &gt;= y; i--){ df.appendChild(createOption(i, i)); } clearChildren(sel_year); sel_year.appendChild(df); } sel_month.onchange = recalculateDays; generateMonths(); recalculateDays(); generateYears(); cont.appendChild(sel_day); cont.appendChild(sel_month); cont.appendChild(sel_year); } </code></pre> <p>Do i need to get javascript to select the result manually for PHP to recognize it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload