Checkbox if corresponding checkbox is checked

Hi Experts,

I have a table with the dynamic fields (can be added by the user) and the structure is like this:

<table>
<tr>
<td><input name="key[]" value="" type="checkbox"></td>
<td><input name="index[]" value="" type="checkbox"></td>
</tr>

<tr>
<td><input name="key[]" value="" type="checkbox"></td>
<td><input name="index[]" value="" type="checkbox"></td>
</tr>

<tr>
<td><input name="key[]" value="" type="checkbox"></td>
<td><input name="index[]" value="" type="checkbox"></td>
</tr>

<tr>
<td><input name="key[]" value="" type="checkbox"></td>
<td><input name="index[]" value="" type="checkbox"></td>
</tr>
</table>

Open in new window


What I want is that the index key can only be checked if the corresponding key checkbox is checked, if the key checkbox is unchecked it should make sure to uncheck the index key as well.

I am really confused. How can I do it? thanks
Rahul SehrawatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
As far as JavaScript knows, every 'key[]' and every 'index[]' are the same.  PHP will recognize that as array syntax but javascript just sees them as identical strings.  You have to do something to make them unique for JavaScript.  The usual way is to number them like 'key[1]' and 'index[1]', 'key[2]' and 'index[2]'.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rahul SehrawatAuthor Commented:
Thanks for the idea. It really helped me alot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.