Uncheck the checked checkbox when clicked in javascript

The problem: When I click on checked checkbox they should get unchecked.


jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="abc.js"></script>
<script type="text/javascript" src="dat.gui.min.js"></script>
</head>

<body onload="gui();">

</body>
</html>

Open in new window


abc.js
var gui_control = function () {

    this.option1=false;
    this.option2=false;
    this.option3=false;    
}

function gui()
{
var gui_controls=new gui_control();
var gui = new dat.GUI({autoPlace:true}); 


gui.add(gui_controls,'option1').listen().onChange(function(value) { gui_controls.option1 = true; gui_controls.option2 = false; gui_controls.option3 = false; } );
gui.add(gui_controls,'option2').listen().onChange(function(value) { gui_controls.option1 = false; gui_controls.option2 = true; gui_controls.option3 = false; } );
gui.add(gui_controls,'option3').listen().onChange(function(value) { gui_controls.option1 = false; gui_controls.option2 = false; gui_controls.option3 = true; } );
}

Open in new window


Please download dat.gui.min.js from attachment.
dat.gui.min.js
Pradip ShenolkarAsked:
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.

sammySeltzerCommented:
Very hard to tell what you are trying to do but can't you do it with jquery or just plain javascript?
Pradip ShenolkarAuthor Commented:
No I can't use plain javascript or jquery.
I need to use dat.gui library
sammySeltzerCommented:
Ok, sorry I can't help you then.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Pravin AsarPrincipal Systems EngineerCommented:
From the description of the problem, looks like you want only one value selected.
So instead of using checkbox control, can  you use radio control ??
In that case, you do not need have any javascript.
Robert SchuttSoftware EngineerCommented:
Finally found the correct way to do it I think:
function gui()
{

    var gui_controls=new gui_control();
    var gui = new dat.GUI({autoPlace:true});

    var gui_opt1 = gui.add(gui_controls,'option1');
    var gui_opt2 = gui.add(gui_controls,'option2');
    var gui_opt3 = gui.add(gui_controls,'option3');

    gui_opt1.onChange(function(value) { if (value) { gui_opt2.setValue(false); gui_opt3.setValue(false); } } );
    gui_opt2.onChange(function(value) { if (value) { gui_opt1.setValue(false); gui_opt3.setValue(false); } } );
    gui_opt3.onChange(function(value) { if (value) { gui_opt1.setValue(false); gui_opt2.setValue(false); } } );
}

Open in new window

live example here: http://schutt.nl/ee/Q_28645759/

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
Pradip ShenolkarAuthor Commented:
@Robert Schutt
 Thanks alot.
 It works as I wanted.
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.