(i am a beginner in javascript)I have 11 checkboxes in a form along with 11 text boxes/text fields beside each checkbox with display:none(text fields) in css. I am trying to display particular text field when user clicks on the respective checkbox using javascript but it is not showing for all checkboxes it is working only for first checkbox. here is my html code:
<label class="container2">I-A
<input type="checkbox" value="IA" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">I-B
<input type="checkbox" value="IB" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">I-C
<input type="checkbox" value="IC" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">I-D
<input type="checkbox" value="ID" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">II-A
<input type="checkbox" value="IIA" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">II-B
<input type="checkbox" value="IIB" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">II-C
<input type="checkbox" value="IIC" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">II-D
<input type="checkbox" value="IID" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">III-A
<input type="checkbox" value="IIIA" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">III-B
<input type="checkbox" value="IIIB" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
<label class="container2">III-C
<input type="checkbox" value="IIIC" name="checkbox[]" id="mycheck" onclick="myFunction()">
<span class="checkmark"></span>
</label>
<input type="text" name="dep[]" id="field">
this is my javascript:
function myFunction(){
var checkBox=document.getElementById("mycheck");
var field= document.getElementById("field");
if(checkBox.checked== true){
field.style.display="inline";
}
else{
field.style.display="none";
}
}