How to add new option to menu in javascript (dat.gui) ?

I have following jsp page, on which I am calling js function gui().
The problem : I want to add new "option" in the menu at runtime.
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});

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

Open in new window


I have tried following, but its not working.
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('option4');">

</body>
</html>

Open in new window


abc.js
var gui_control = function () {

    var opt4=arguments[0];
    this.option1=false;
    this.option2=false;
    this.option3=false;
    this.opt4=false;
}


function gui()
{
	var opt4=arguments[0];
	
    var gui_controls=new gui_control(opt4);
    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');

    var gui_opt4 = gui.add(gui_controls,opt4);   
}

Open in new window


Please download dat.gui.min 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.

Robert SchuttSoftware EngineerCommented:
Only one change needed, line 7 in abc.js should be:
this[opt4]=false;

Open in new window

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:
Thank you so much....

Just wanted to know what does [opt4] means ?
Does it take value of 'opt4' variable ?
Robert SchuttSoftware EngineerCommented:
yes, in javascript you have the option to access properties in 2 ways:
this.option1=false; // direct access

var optname = 'option1';
this[optname]=false; // access same property indirectly

Open in new window

so because your opt4 is a variable holding the name of the property you want to access you can't use the first way here, only the second way.
Pradip ShenolkarAuthor Commented:
Thanks for explanation.
I dint knew this before.
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.