Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:27:17+00:00 2026-06-01T18:27:17+00:00

i have been working on this code ! and i couldn’t done it right

  • 0

i have been working on this code !
and i couldn’t done it right .

what i want is the text box to be enabled when the corresponding checkbox is checked .
but when apply the function nothing happens 🙁

in my code the text and check boxes are dynamically generated from database using php .
here is my code :

<div><div class="ac-container">

<div id="accordion">

<?php

$qry="SELECT * FROM catalog";
$result= mysql_query($qry);
if($result){
while($info = mysql_fetch_array($result))
{

print "<h3><a href=\"\#\"> cat:".$info['name']."</a></h3><div>";

$qryitem="SELECT * FROM item WHERE Id=". $info['Cid'];
$resultitem=mysql_query($qryitem);
if($resultitem){

?>

<form name="form1" id="form" method="post" action="manage_item_action.php"  >
<?php
while($info=mysql_fetch_array($resultitem))
{
?>
<input type="checkbox"  id="checkB" name="op[]" value="<?php echo $info['Id'];?>" />   <?php echo $info['name'];?>
<label> Quantity <input disabled="disabled" id="textB" type="text" 
name="Quantit[]" value="<?php echo $info['Quantity'];?>"/>
</label>
<script>



 checkBoxes=document.form1.elements['op[]'];
 textBoxes=document.form1.elements['Quantit[]'];
 for(var i=0 ; i<checkBoxes.length;i++){
 checkBoxes[i].onchange = function() {
 textBoxes[i].disabled =!(this.checked);};


 }

 </script>



<br/>

        <?php
        } 
    }


 else echo "There are no items.";

 print "</div>";



}
}


?>

</div>

<input type="submit" value="update" name="submit"/>
<input type=reset value="clear"></td></tr> </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:27:19+00:00Added an answer on June 1, 2026 at 6:27 pm

    The problem you are having is that inside your event handler the variable i is not defined. To overcome this problem, you could add a property to each checkbox to save what index they are referring to:

    checkBoxes=document.form1.elements['op[]'];
    textBoxes=document.form1.elements['Quantit[]'];
    for(var i=0 ; i<checkBoxes.length;i++)
    {
        checkBoxes[i].myIndex = i;
        checkBoxes[i].onchange = function() {
            textBoxes[this.myIndex].disabled =!(this.checked);
        };
    }
    

    Other methods to solve this problem: http://www.howtocreate.co.uk/referencedvariables.html

    Your code is still pretty messed up. For instance you are generating too many closing <div/>-tags with your first print-statement. I would suggest you just remove the PHP-code from your question, as the question is only related to html and javascript.

    I would also suggest to use a library for manipulating DOM elements like jQuery.

    When writing and debugging javascript, you should always make sure that you get error messages. “nothing happens” is a sign that you are just ignoring errors. For Firefox download the addon Firebug. Safari also has developer tools that you can activate in the settings. Using these tools will make it very easy to spot and solve problems like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this code but I can't find out what is
Have been working on this question for a couple hours and have come close
I have been working on this problem for 2 days now and it's an
I have been working on this for days but I don't get it so
I have been working on this problem for a while now. I am trying
I have been working on this for 24 hours now, trying to optimize it.
I have been working on this for some time now and just cant quite
i have been working on this sub-menu for 8 hours now, the last little
I have been working on this for some time. The script does work and
So I have been working on this project for a short while now. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.