There is such a code
<select> <option>Пункт 1</option> <option>Пункт 2</option> </select> How to write a condition, if Item 2 is selected, then execute a code block.
There is such a code
<select> <option>Пункт 1</option> <option>Пункт 2</option> </select> How to write a condition, if Item 2 is selected, then execute a code block.
First, supply the <option> elements with the value attribute. Then add a select event change handler.
<select id="sel"> <option value="1">Пункт 1</option> <option value="2">Пункт 2</option> </select> On jQuery, the rest will look like this:
$("#sel").change(function(){ if($(this).val() == 2){ //выполняем код при выборе "Пункт 2" alert("Выбран Пункт 2"); } }); For this html you can use and just pure Javascript. If the second option is selected, then its sequence number from all options will be 1 (counting from 0) and execute the code from the condition block.
<select id="sel"> <option value="1">Пункт 1</option> <option value="2">Пункт 2</option> </select> Javascript:
<script> if (document.getElementById("sel").options.selectedIndex == 1) { //execute code } </script> Source: https://ru.stackoverflow.com/questions/601201/
All Articles