Difference between revisions of "JavaScript"
(New page: <h2>Javascript: PG Code Snippet</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This code snippet shows the essential PG code to include javascript in a ...) |
(added historical tag) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">It is not recommended to use javascript in a problem currently.</p> |
||
+ | |||
<h2>Javascript: PG Code Snippet</h2> |
<h2>Javascript: PG Code Snippet</h2> |
||
Line 6: | Line 10: | ||
<p style="text-align:center;"> |
<p style="text-align:center;"> |
||
[[IndexOfProblemTechniques|Problem Techniques Index]] |
[[IndexOfProblemTechniques|Problem Techniques Index]] |
||
+ | </p> |
||
+ | <p> |
||
+ | <em>It might be nice to include a different example than this here.</em> |
||
</p> |
</p> |
||
Line 82: | Line 89: | ||
[[IndexOfProblemTechniques|Problem Techniques Index]] |
[[IndexOfProblemTechniques|Problem Techniques Index]] |
||
</p> |
</p> |
||
+ | |||
+ | [[Category:Problem Techniques]] |
Latest revision as of 08:54, 28 June 2023
It is not recommended to use javascript in a problem currently.
Javascript: PG Code Snippet
This code snippet shows the essential PG code to include javascript in a WeBWorK question. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
It might be nice to include a different example than this here.
PG problem file | Explanation |
---|---|
loadMacros("parserNumberWithUnits.pl"); |
We don't need any changes to the tagging and description or initialization sections of the WeBWorK PG file to include javascript. This particular example, however, involves an answer with units , so we have to include the parser module for that. |
## include javascript to open units ## help window HEADER_TEXT(<<EOF); <script language="javascript" type="text/javascript"> <!-- // function unitspopup() { var url = "/webwork2_files/units.html"; var opt = "height=625,width=600,location=no," + "menubar=no,status=no,resizable=yes," + "scrollbars=yes,toolbar=no,"; window.open(url,'examdata_info',opt).focus(); } // --> </script> EOF |
In the problem set up section we can include any javascript that is to be inserted into the header of the web page that's created by using the |
BEGIN_TEXT Enter 3 kg: \{ ans_rule(10) \} $BR (include \{htmlLink("javascript:unitspopup()","units")\}) |
We can then use the function in the problem; here we include it as a link. |
ANS( NumberWithUnits("3 kg")->cmp() ); |
No changes are needed in the answer and solution section of the file, except any use of the javascript that one uses there. Here we don't have any changes. |