0

I know its kinda duplicate , my am trying to do this in a different way and thus re-posting this question.

What am trying to achieve is , when someone "Un-Check" the OSPF Checkbox .. the Passive Interface Check should also get "Uncheched" automatically. I'm trying to debug why UnChecked is not working, but no luck. Below is my code.

OSPF <input type="checkbox" name="ospfen" id="ospfen_1" onclick="if(this.unchecked){document.getElementById('ospfpassive_1').checked=false;}">&nbsp; Passive Interface<input type="checkbox" name="ospfpassive" id="ospfpassive_1" onclick="if(this.checked){document.getElementById('ospfen_1').checked=true;}"> <br />

I also wanted if someone check the Passive Interface checkbox...the OSPF should get checked and this part of the code is working fine. Only "Un-Check" is not working.

Thanks in advance

1
  • check my answer. You can also separate your javascript code from HTML, it will be cleaner. Commented Jan 7, 2016 at 16:57

4 Answers 4

2

The property unchecked does not exists. So use check checked :)

OSPF <input type="checkbox" name="ospfen" id="ospfen_1" onchange="if(!this.checked){document.getElementById('ospfpassive_1').checked=false;}">

Passive Interface <input type="checkbox" name="ospfpassive" id="ospfpassive_1" onchange="if(this.checked){document.getElementById('ospfen_1').checked=true;}"> <br />

Here is a working example :

https://jsfiddle.net/0mn3mprv/

Sign up to request clarification or add additional context in comments.

1 Comment

I was not aware uncheck property was not there....what I did few sec back to make it working is below ..is for sure ugly and yours is good. thanks OSPF <input type="checkbox" name="ospfen" id="ospfen_1" onclick="if(document.getElementById('ospfen_1').checked==false) {document.getElementById('ospfpassive_1').checked=false;}">&nbsp; Passive Interface<input type="checkbox" name="ospfpassive" id="ospfpassive_1" onclick="if(this.checked){document.getElementById('ospfen_1').checked=true;}"> <br />
1

There's no 'unchecked' property.

Use:

!this.checked

instead.

Comments

0

This might be an easier way to approach it

onclick="document.getElementById('ospfpassive_1').checked = !this.checked;"

this way the other check box's checked property is always the opposite

1 Comment

I dont want always the opposite. What I need is ...If OSPF is selected ...Passive "Can" be selected . If Only Passive is selected ..OSPF get selected automatically which is working. Finally , if ospf and passive both are selected and someone unselect OSPF ....Passive get unselected ...which is broken
0

Checkboxes does not have a property named unchecked. You must verify the value the property named checked.

OSPF 
<input type="checkbox" name="ospfen" id="ospfen_1" onclick="if(!this.checked){document.getElementById('ospfpassive_1').checked=false;}">

&nbsp; 

Passive Interface
<input type="checkbox" name="ospfpassive" id="ospfpassive_1" onclick="if(this.checked){document.getElementById('ospfen_1').checked=true;}"> <br />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.