i need to change the innerHTML text of a option tag, based on the input of an input form. I did it like this but as soon as i write “1” it gets locked up and i cannot write anything else there. It does change the text but it doesn’t allow you to write anything else, or change from 1 to the value of 2 for example.
function change_let_rok() { if (document.kombpred.nn.value = "1") { document.kombpred.obdobi.options[0].innerHTML = "Rok"; } else { document.kombpred.obdobi.options[0].innerHTML = "Let"; } }
The html code is:
<form name="kombpred"> <input style ="display:inline;" name=nn type=text size=15 class='innerc resform' oninput="change_let_rok()"> <select name="obdobi" style="display:inline;"> <option value="let">Let</option> <option value="mesice">Mesice</option> <option value="ctvrtlety">Ctvrtlety</option> <option value="pulroky">Pulroky</option> </select> </form>
Advertisement
Answer
You only have 1 equals sign in your if statement. Should be ‘==’. Also your values for the options should probably be 1,2,3,and 4 respectively.