<script type="text/javascript"> function changeText(){ var userInput = document.getElementById('sel').selectedIndex.value; document.getElementById('view').innerHTML = userInput; } </script> where error?
This is a working code: <form method="post" action="" style="margin:0px"> <select name="sel" id="sel" onChange="changeText()"> <option value="1">1 selected</option> <option value="2">2 selected</option> <option value="3">3 selected</option> </select> <div id="view"></div> </form> <script type="text/javascript"> function changeText(){ var userInput = document.getElementById('sel').options[document.getElementById('sel').selectedIndex].value; document.getElementById('view').innerHTML = userInput; } </script> Code (markup):
Then instead of: var userInput = document.getElementById('sel').options[document.getElementById('sel').selectedIndex].value; Code (markup): use: var userInput = document.getElementById('sel').options[document.getElementById('sel').selectedIndex].text; Code (markup):
<script type="text/javascript"> function changeText(){ var chosenoption=document.getElementById("sel").options[document.getElementById('sel').selectedIndex].value; if (chosenoption.value="USD") { document.getElementById("p1").innerHTML="180 USD" document.getElementById("p2").innerHTML="200 USD" document.getElementById("p3").innerHTML="290 USD" } if (chosenoption.value="SAR") { document.getElementById("p1").innerHTML="252 SAR" document.getElementById("p2").innerHTML="280 SAR" document.getElementById("p3").innerHTML="504 SAR" } } </script> where error?