| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Adding JavaScript to an html page that includes an applet

Page history last edited by Mike May, S.J. 13 years, 2 months ago

One of the nice feature of GeoGebra is that it is Javascript aware.

That means that we can have a web page with javascript controls of the applet.

 

 

In the pictured example, beneath the applet is a line that controls the viewing window, followed by a line that allows the user to set the function and the starting point, followed by a line that allows the user to load preset examples.

 

Looking at the image of a web page for this applet shows text we would want for the students to understand what is going on. It also shows three javascript control panels that make the applet more user friendly. There is a panel that controls the viewing window, generated by

 

      <script type="text/javascript">
function setView(objName) {
  var applet = document.ggbApplet;
  var LowX = document.ViewForm.LowXField.value;
  var HighX = document.ViewForm.HighXField.value;
  var LowY = document.ViewForm.LowYField.value;
  var HighY = document.ViewForm.HighYField.value;
  applet.setCoordSystem(LowX, HighX, LowY, HighY);
}
      </script>
      <form name="ViewForm" onsubmit="setView('T');  return false;">
Min X = <input name="LowXField" size="5" onchange="setView('T');"
 value="-6" type="text">
Max X = <input name="HighXField" size="5"
 onchange="setView('T');" value="8" type="text"> 
Min Y = <input name="LowYField" size="5" onchange="setView('T');" 
value="-4" type="text"> 
Max Y = <input name="HighYField" size="5"
 onchange="setView('T');" value="5" type="text"> 
<input value="Set Window" onclick="setView('T');" type="button"> 
</form>



There is a panel that controls the function and starting point, generated by

 

<script type="text/javascript">
 function setFunction(objName) {
  var applet = document.ggbApplet;
  var f= document.functionForm.setFunctionField.value;
  applet.evalCommand("f(x)="+f);
  var X0= document.functionForm.setX0.value;
  applet.evalCommand("X0=("+X0+",0)");
  }
</script>

<form name="functionForm" onsubmit="setFunction('T');  return false;"> 
<input value="set values" onclick="setFunction('T');" type="button">  
f(x) = <input name="setFunctionField" onchange="setFunction('T');" 
    size="30" value="cos(x)-x/5" type="text"> 
X0 = <input name="setX0" size="10"
     onchange="setFunction('T');" value="1" type="text"> 
</form>



There is a panel that allows the user to load pre-made examples, generated by

 

<script type="text/javascript">
function formHandler(form){
var f = document.examples.site.value;
document.functionForm.setFunctionField.value =f
document.ggbApplet.evalCommand("f(x)="+f);
  }
</script>

<center>
      <form name="examples">
        <select name="site" size="1">
        <option value="">Examples</option>
        <option value="x^4-2x^3-x^2-2x+2">x^4-2x^3-x^2-2x+2</option>
        <option value="x^4-3x^3+x^2+2x-2">x^4-3x^3+x^2+2x-2</option>
        <option value="x^2+.5">x^2+.5</option>
        <option value="cbrt(x)">cube root of x</option>
        </select>
        <input value="Load Example"
 onclick="javascript:formHandler(this)" type="button"></form>
</center>

 

Comments (0)

You don't have permission to comment on this page.