lundi 5 septembre 2016

Enable input field after checkbox is checked in list of checkboxes

I have a list of data getting from database, and i want to enable input field on checked checkbox. However its working only with the first line. Here is HTML code:

<?php
    require_once('inc/config.php');
    include 'verification/verify_form_details.php';
?>
<html>
<head>
  <title>getElementById example</title>
  <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
    <script>
        $(document).ready(function () {
            document.getElementById('checkbox').onchange = function() {
                document.getElementById('field').disabled = !this.checked;
            };
        });
    </script>
</head>
<body>
    <?php 
        $result2 = getProcessID();
    ?>
    <label>Process: <small style="color:red;">*</small>             
    <?php 
        while ($row = mysql_fetch_array($result2))
        {
            $row[0] = cleanOutputData($row[0]);
    ?>      
    <div>       
        <label>
        <input type="checkbox" id="checkbox" name="process[]" id=<?php echo $row[0] ?>  value=<?php echo $row[0]?> /><?php echo $row[0] ?>
        </label>                                        

        <label>
        <input type="text" id="field" disabled name="number[]" id=<?php echo $row[0] ?> />
        </label>

    </div>
    <?php
        }
        mysql_free_result($result2);
    ?>
    </label>
</body>
</html>

And javascript function:

<script>
    $(document).ready(function () {
        document.getElementById('checkbox').onchange = function() {
            document.getElementById('field').disabled = !this.checked;
        };
    });
</script>

Any ideas how i can do it? Thank you

Aucun commentaire:

Enregistrer un commentaire