How to attach an event-handler to a checkbox objet ?

169 views
Skip to first unread message

Gilles Dubois

unread,
Jan 25, 2015, 4:25:33 AM1/25/15
to jsxg...@googlegroups.com
Hello everybody !
I tried the 'on' method without success.
var checkbox1 = board.create('checkbox', [-3.8, 3.8, '(y,x)'], {});
checkbox1.on('down',function (){window.alert("box touched !");});
parameter 'mousedown' doesn't work either.
 Unable to find any example in the documentation.
My need : to do something when I check/uncheck some checkbox(es).
Examples given in the doc aren't event handlers, they construct points according value of the control. Actually they are not triggering anything.
The radio buttons do not exist natively in jsxgraph (it's a pity), so  I want to use checkboxes instead, checking and unchecking manually.
Of course I can always place a radio boutton outside the graphic zone, what I will do if I cannot have any satisfactory answer.
Thanx for your help.

Alfred Wassermann

unread,
Jan 25, 2015, 5:16:20 PM1/25/15
to jsxg...@googlegroups.com
Up to now, not many events are registered for the HTML form elements. We have
  • checkbox: on('change', ...)
  • input: on('input', ...)
  • button: on('click', ...)

If more flexibility is needed, there is nothing wrong to use HTML code in JSXGraph text elements, like

var t = board.create('text', [0, 1, '<input type="radio" name="xy" value="1"> ...']);

Best wishes, Alfred

Gilles Dubois

unread,
Jan 26, 2015, 2:55:10 PM1/26/15
to jsxg...@googlegroups.com


Thank you Alfred for your answer.
Actually 'external' html5 controls interact with 'inside box' objects using the same .js file. So I solved my problems this way:
 
        <div id="box" class="jxgbox" style="width:500px; height:500px;"></div><br />
        <input type="radio" name="applin" value="1" checked onclick="handleClick(this);">(y,x)
        <input type="radio" name="applin" value="2"  onclick="handleClick(this);">(-y,x)
        <input type="radio" name="applin" value="3"   onclick="handleClick(this);">(2x,2y)
        <input type="radio" name="applin" value="4"  onclick="handleClick(this);">(3x,x+2y)<br />
        <button type="button" onclick="resultat();"> Théorie</button>
        <script src="vectprop1.js"></script>

Gilles Dubois

unread,
Feb 16, 2015, 5:37:27 AM2/16/15
to jsxg...@googlegroups.com
Bonjour
Can you answer this very simple question :
Do we have any event handler for jsxgraph sliders corresponding to
on, onmousedown, down, change etc...
and how to implement it ???
Documentation is not quite explicit without examples at all.
I want to actualize the board when i change the value of some slider.
Points with coordinates which are function of the value of the slider are updated, others objects are not which can indirectly depend on this value, for example arrays of points which have been calculated with some slider value and need to be recalculated.
Merci .
Gilles

 

Alfred Wassermann

unread,
Feb 16, 2015, 5:53:03 AM2/16/15
to jsxg...@googlegroups.com
You can use the events "up" and/or "move":

var a = board.create('slider', [[1,4],[2.5,4],[0, 0.25, 0.3]],{name:'a'});
a
.on('up',function(){ console.log("up"); });
a
.on('move',function(){ console.log("move"); });


Best wishes,
Alfred

Gilles Dubois

unread,
Feb 16, 2015, 6:35:00 AM2/16/15
to jsxg...@googlegroups.com
Thank you !
Reply all
Reply to author
Forward
0 new messages