I have node/express Application which is using ejs template as views. I have a drop down in ejs which is generated dynamically and it is working fine. I want to show/display the value selected from dropdown in a text box but my code is not working . I am able to do it in couple of ways in plain HTML/JS but not working in ejs.
Here is my code:
It seems run() is getting executed on selecting option from dropdown menu .
Any help will be greatly appreciated
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" http-equiv="refresh" content="7" >
<title>Flow Meter Dashboard </title>
</head>
<body>
<h1> <%= title%></h1> <br>
<ul>
<% for(var key in Data){ %>
<% var k=key;%>
<%var v=Data[key];%>
<li><%= k %> <%=":"%> <%=v%></li>
<%} %>
</ul>
<form action="http://127.0.0.1:8081/" method="POST">
Water Recharge Amount: <br>
<!-- <input type="text" name="WaterBalance" value= wb > -->
<input type="submit" name="Recharge_Amount" value="100" >
<input type="submit" name="Recharge_Amount" value="200"><br>
<br><input type="submit" name="Recharge_Amount" value="500" >
<input type="submit" name="Recharge_Amount" value="1000"><br>
<br> Switch ON RO Purifier: <input type="submit" name="Switch_ON" value="ON" > <br>
<br>Switch OFF RO Purifier: <input type="submit" name="Switch_OFF" value="OFF" > <br>
</form>
Select RO<br>
<input type="text" id="srt" placeholder="select RO id"><br>
<%function run() {%>
<%var e = document.getElementById("drpdwn");%>
<%var strUser = e.options[e.selectedIndex].text;%>
<%document.getElementById("srt").value =strUser;%>
<% }%>
<br>
<select id="drpdwn" onchange="run();">
<option value="Select_RO" selected>Select RO</option>
<%for(var i=0;i<ro.length;i++){ %>
<option value='<%= ro[i]%>'/><%=ro[i]%> </option>
<% }%>
</select>
</body>
</html>
<option value='<%= ro[i]%>'/><%=ro[i]%> </option>