How to make a checkbox enable or disable a text field in several cases

I did something like this.

<html>
<head>
<script type="text/javascript">
<!--
function toggleTB(what){
if(what.checked){document.theForm.theTB.disabled=1}
else{document.theForm.theTB.disabled=0}}
//-->
</script>
</head>
<body>
<form name="theForm">
<input type="checkbox" name="theCB" onClick="toggleTB(this)">Toggle The Text Box<br>
<input type="text" name="theTB" value="asdf">
</form>
</body>
</html>

But this is used only once. I need this function repeatedly on other lines, just as I can use this function several times.

My form is as follows:

 <tr>    
 <td style="border-top:none; text-decoration:underline;" >Specific operations/procedures</td>
 <td>
 <input type="checkbox" name="sd3[]" value="mfi_nam9" />Other(please specify):
 <input type="text" name="mfi_nam9" class="text required" id="mfi_name" 
 </td>
 </tr>
 <tr>    
 <td style="border-top:none; text-decoration:underline;" >General principles/strategies</td>
 <td>
 <input type="checkbox" name="sd2[]" value="mfi_nam8" />Other(please specify):
 <input type="text" name="mfi_nam8" class="text required" id="mfi_name" 
 </td>
 </tr>

I will be waiting for an answer to ur, and I am very grateful to you for helping me earlier, and I hope that you will help me too this time.

0
source share
4 answers

Read this article.

I would prefer jQuery

Here is a demo

Another DEMO

+1
source

, function toggleTB(what,elid) { if(what.checked) { document.getElementById(elid).disabled=1 } else { document.getElementById(elid).disabled=0 } }  
2. HTML
<input type="checkbox" name="sd3[]" value="mfi_nam9" onClick="toggleTB(this,'mfi_name1')" / > Other(please specify): <input type="text" name="mfi_nam9" class="text required" id="mfi_name1" / >  
, , , php.

0

onclick

<input type="checkbox" name="sd2[]" value="mfi_nam8" onClick="toggleTB(this)" />Other(please specify):

toggleTB

function toggleTB(what){
    what.form.elements[what.value].disabled = what.checked;
}
0

Java Script:

function toggleTB(what){

var theTB = document.getElementById(what.value); 

if(what.checked){theTB.disabled=1}
else{theTB.disabled=0}

}

HTML:

<table>
    <tr>    
     <td style="border-top:none; text-decoration:underline;" >Specific operations/procedures</td>
     <td>
     <input type="checkbox" name="sd3[]" onClick="toggleTB(this)" value="mfi_nam9"  />Other(please specify):
     <input type="text" name="mfi_nam9"  id="mfi_nam9" class="text required" />
     </td>
     </tr>
     <tr>    
     <td style="border-top:none; text-decoration:underline;" >General principles/strategies</td>
     <td>
     <input type="checkbox" name="sd2[]" onClick="toggleTB(this)" value="mfi_nam8" />Other(please specify):
     <input type="text" name="mfi_nam8" id="mfi_nam8" class="text required" />
     </td>  
     </tr>

</table>

: , NAME, .

, BOX CHECK BOX. , BOX, - , - , , .

, , JAVA Script, -

if(what.checked){theTB.disabled=0} // have placed 0 in place of 1
  else{theTB.disabled=1} // have placed 1 in place of 0
}

HTML INPUT-BOX -  

, (/) , , , click , :)

0
source

All Articles