Note that there are some explanatory texts on larger screens.

plurals
  1. POError javascript function to get value out of static php drop down
    primarykey
    data
    text
    <p>I made the dropdown with PHP which works fine. When the selected item changes, I call the function changePeriod().</p> <pre><code>$options[0] = '--period--'; $options[1] = 'Daily'; $options[2] = 'Weekly'; $options[3] = 'Monthly'; &lt;td&gt;&lt;?php echo form_dropdown('period', $options, '0', 'id="period" onchange="changePeriod()"'); ?&gt;&lt;/td&gt; </code></pre> <p>Here you can see the HTML source code which is a result of the code above. </p> <pre><code>&lt;td&gt; &lt;select name="period" id="period" onchange="changePeriod()"&gt; &lt;option value="0" selected="selected"&gt;--period--&lt;/option&gt; &lt;option value="1"&gt;Daily&lt;/option&gt; &lt;option value="2"&gt;Weekly&lt;/option&gt; &lt;option value="3"&gt;Monthly&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; </code></pre> <p>In this function I need to get the value of the selected item, but the 2 alerts above the switch both give <strong>Undefined</strong> as a result. Does anyone has an idea why I get undefined and not the values of the selected option? It worked with a dynamic dropdown filled with a foreach from the database. </p> <pre><code>function changePeriod() { alert(document.getElementById("period").selectedIndex); alert(document.getElementById("period").value); switch (document.getElementById("period").selectedIndex) { case 1: alert("daily"); break; case 2: alert("weekly"); break; case 3: alert("monthly"); break; } } </code></pre> <p><strong>Basically:</strong> Why can't I get the values of the selected option and how can I fix it?</p> <p>Thanks for helping.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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