php - enable / disable textbox depending on checkbox - javascript -


hi have problem when try make php javascript function want make textbox go enable / disable depending on checkbox on left side

this code

<html> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title></title>     <script type="text/javascript">         function enable_txtbox(id){             if(document.getelementbyid(id).disabled){                 document.getelementbyid(id).disabled=false;                 var x = document.getelementbyid(id).disabled;                 document.getelementbyid("demo").innerhtml=x;             }             else                 document.getelementbyid(id).disabled=true;         }     </script> </head> <body>     <form method="get">     <table>         <tbody>             <tr>                 <td>nama gejala</td>                 <td>:</td>                 <td><input type="text" name="nama"></td>             </tr>             <tr>                 <td>jenis gejala</td>                 <td>:</td>                 <td><select name="jenis">                         <option value="0">umum</option>                         <option value="1">khusus</option>                     </select></td>             </tr>         </tbody>     </table>         <table>             <thead>                 <tr>                     <td>penyakit yang berhubungan</td>                     <td>:</td>                 </tr>               </thead>             <tbody>                 <?php                      $id=1;                     while($row = mysqli_fetch_array($result)){                         $id=$row['id'];                         echo "<tr>";                         echo "<td><input type='checkbox' name='chk$id' value='$id' onclick='enable_txtbox('".$id."')'>".$row['nama']."<br></td>";                         echo "<td>nilai kepastian</td>";                         echo"<td>:</td>";                         echo "<td><input type='text' name='cf".$id." id='$id' disabled='disabled'></td>";                         echo "</tr>";                     }                     mysqli_close($con);                 ?>             </tbody>         </table>         <table>             <tbody>                 <tr>                     <p id="demo"></p>                     <td><input type="submit"></td>                 </tr>             </tbody>         </table>     </form> </body> </html> 

ps : have more 1 checkboxes , textboxes depending on database file

thanks before , forgive me bad english skill :)

you should use jquery check whether checkbox checked. have checkbox id='idtag', , check whether checkbox checked or not.

$('#idtag').is(":checked") 

this returns true should checkbox checked; moment on use jquery either show hidden, or append div. text input box has id 'textid'.

method one:

if($('#idtag').is(":checked"))     $("#textid").css("display", "block"); //if show block.  if($('#idtag').is(":checked"))     $("#textid").fadein("slow"); //gives nice effect well. 

method two:

<div id='div'>    <input type='checkbox' id='idtag' value='checkbox'/> </div> <script>    if($('#idtag').is(":checked"))        $("#div").append("<input type='text' placeholder='textbox' />"); </script> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -