Function Checkbox checked by scrip.
- <!DOCTYPE html>
- <html>
- <title>Test</title>
- <meta charset="UTF-8">
- <body>
- <div align='center'>
- <form id="myForm" align='center'>
- <label><input type="checkbox" name="OD" id="OD" value="1" onchange="CheckedBox(this.value)"> ฝพอ.</label><br>
- <label><input type="checkbox" name="IF" id="IF" value="2" onchange="CheckedBox(this.value)"> ฝบง.</label><br>
- <label><input type="checkbox" name="DS" id="DS" value="3" onchange="CheckedBox(this.value)"> ฝอบ.</label><br>
- <br><hr>
- </form>
- <br>
- <form id="myForm2" align='center'>
- <label><input type="checkbox" name="checkbox3" id="checkbox3" value=""> หน.งทส.</label><br>
- <label><input type="checkbox" name="checkbox4" id="checkbox4" value=""> หน.งพม.</label><br>
- <label><input type="checkbox" name="checkbox5" id="checkbox5" value=""> หน.งสป.</label><br>
- <label><input type="checkbox" name="checkbox6" id="checkbox6" value=""> หน.งบง.</label><br>
- <label><input type="checkbox" name="checkbox7" id="checkbox7" value=""> หน.งอบ 1.</label><br>
- <label><input type="checkbox" name="checkbox8" id="checkbox8" value=""> หน.งอบ 2.</label><br>
- </form>
- </div>
- <script></script>
- </body>
- </html>
- function CheckedBox(value) {
- if(value == 1){
- if(document.getElementById("OD").checked){
- document.getElementById("checkbox3").checked = true;
- document.getElementById("checkbox4").checked = true;
- document.getElementById("checkbox5").checked = true;
- } else {
- document.getElementById("checkbox3").checked = false;
- document.getElementById("checkbox4").checked = false;
- document.getElementById("checkbox5").checked = false;
- }
- } else if (value == 2){
- if(document.getElementById("IF").checked){
- document.getElementById("checkbox6").checked = true;
- } else {
- document.getElementById("checkbox6").checked = false;
- }
- } else if (value == 3){
- if(document.getElementById("DS").checked){
- document.getElementById("checkbox7").checked = true;
- document.getElementById("checkbox8").checked = true;
- } else {
- document.getElementById("checkbox7").checked = false;
- document.getElementById("checkbox8").checked = false;
- }
- } else {
- document.getElementById("OD").checked = false;
- document.getElementById("IF").checked = false;
- document.getElementById("DS").checked = false;
- document.getElementById("checkbox3").checked = false;
- document.getElementById("checkbox4").checked = false;
- document.getElementById("checkbox5").checked = false;
- document.getElementById("checkbox6").checked = false;
- document.getElementById("checkbox7").checked = false;
- document.getElementById("checkbox8").checked = false;
- }
- }
No comments:
Post a Comment