1

You can choose option a,b,c,d. If you choose option b,"Have a beautiful day!" will appears.

<div class="main-div">
    <optgroup label="Select an option">
        <select name = "dropdown" class="dropdown1" id="selectOption" placeholder="Choose">
            <option value = "a" selected>a</option>
            <option value = "b">b</option>
            <option value = "c">c</option>
            <option value = "d">d</option>
        </select>
    </optgroup>
</div>

How to set valueOption ('a', 'b','c', or 'd') so to use the following code?

<% if (valueOption === 'b') { %>
    <h2> Have a beautiful day! </h2>
<% }%>
LC4U
  • 15
  • 3
  • 1
    The ejs runs on server but the dropdown is in the browser. Are you wanting to submit the selected value to server to do this? If you just want to do this in browser you need to rethink how to process all this client side by matching the selected value to an element to display – charlietfl Mar 25 '21 at 22:36

1 Answers1

0

You should use the onchange event.

Here is an example with jquery jQuery get value of select onChange

Gidon Wise
  • 1,896
  • 1
  • 11
  • 11