Click here to Skip to main content
15,883,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i select first checkbox then automatically checked second checkbox.
how to store second checkbox id in first checkbox using javascript
Posted
Comments
jaket-cp 13-Jan-15 8:17am    
Not sure what you mean by:
how to store second checkbox id in first checkbox using javascript

You can do it like this:

HTML
<input type="checkbox" id="Check" ></input>
<input type="checkbox" id="Check1">
</input>

In JavaScript:

JavaScript
function function1(){
  document.getElementById("Check1").checked = true;
}
 
Share this answer
 
v2
Comments
[no name] 13-Jan-15 8:15am    
@Sanket Thanks for Formatting, but you missed the onclick() event.
Try this:
XML
<!DOCTYPE html>
<html>
<head>
<script>
function myfunction()
{
    document.getElementById('checkbox2').checked = document.getElementById('checkbox1').checked
}
</script>
</head>
<body>
<input type="checkbox" id="checkbox1" onclick="myfunction();">Checkbox1
<input type="checkbox" id="checkbox2">Checkbox2
</body>
</html>
 
Share this answer
 
Comments
Nishant.Chauhan80 14-Jan-15 2:38am    
how to dynamically store id in one checkbox
Peter Leow 14-Jan-15 2:45am    
I do not get you. Store id of a checkbox in another checkbox? Where of the other checkbox? An id is supposed to be unique throughout a web document. Furthermore, the checkbox is not meant for storage purpose. Are you trying to achieve something?
Nishant.Chauhan80 14-Jan-15 2:59am    
sir spouse i have one anchor tag and two checkboxes when i click on anchor Tag automatically checked but checked only checkbox store id in anchor tag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900