0

I have a problem with one of my select tags. I am trying to make a input type text read only and a text area readonly alternating between the two depending on the a value of a select. But my select tag is stuck and cant change it when i click on it. Also when i refresh my page the select tag is on option "Onderwerp" instead of "Titel" but my first option is "Titel".

My Javascript function:

<script type="text/javascript">
   function read()
   {
       current=document.getElementById("soortvraag");
       if(current.value="onderwerp")
       {
          document.getElementById('auteur').readOnly = true;
          document.getElementById('antwoord').readOnly = false;
       } else {
          document.getElementById('auteur').readOnly = false;
          document.getElementById('antwoord').readOnly = true;
       }
   }
</script>

My Html:

<p><label for="soortvraag">Soortvraag:</label> 
<p><select id="soortvraag" onchange="read()" name="soortvraag">
     <option value="titel">Titel</option>
     <option value="onderwerp">Onderwerp</option>
</select></p>  
<p><label for="vraag">Titel:</label>
   <label style="padding-left:95px;"for="auteur">Auteur:</label>
</p>
<p><input type="text" name="vraag" pattern=".{4,20}" required title="4 tot 20 Tekens" value=""> 
   <input type="text" id="auteur" name="auteur" value=""></p>
<p><label for="antwoord">Antwoord:</label></p>
<p><textarea id="antwoord" name="antwoord" style="width:400px;height:100px;"></textarea></p>

And on my body i have:

<body onLoad="read()">

1 Answer 1

1

You're not correctly comparing the value of your select element.

This assignment (=):

if(current.value = "onderwerp")

Should be a comparision (==):

if(current.value == "onderwerp")

This causes all the issues you're describing.

1
  • It works like charm now! thank you very much :) won't be making that mistake again ;)
    – Maantje
    Sep 24, 2014 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.