Calling advanced_testcase::resetAllData() in the setUp of the events test fixed this problem whatever it was.
Itamar Tzadok
المواضيع التي نشرها Itamar Tzadok
If you need ot make it work on a course page, you can add it to a label resource or to an html block. The javascript has to be in a script tag (see other post). Make sure the editor doesn't strip off the tag. If it does, turn off the editor in your user profile when editing this label/block. You also need to add some html to display input box and submit button. Again, you can google for simple examples. Basically, you need something like:
<input id="my-calculator-input" type="text" />
<div id="my-calculator-result" style="width:240px;background:#CCFF99;border:1px solid #DDD;margin:10px 0;"> </div>
<div><input type="button" onclick="myCalculator();" value="Show result" /></div>
<script>
function myCalculator() {
var data = [];
data[30] = 89;
data[33] = 95;
var inputval = document.getElementById("my-calculator-input").value;
// Check that data for inputval is defined.
if (typeof data[inputval] == 'undefined') {
var result = 'No results for specified input';
} else {
var result = data[inputval];
}
document.getElementById("my-calculator-result").innerHTML = result;
}
</script>
hth
<script>
var data = [1, 2, 3];
...
</script>
This way it will apply only to that template but it may require you to turn off editor when editing the template as the editor may strip off the script tag.
Alternately, you put the javascript in the Javascript tab of the Database activity. More convenient for editing, but it will apply to all 3 templates (list, single, edit) unless you condition its execution in some way. One way is to put it in a question and then add to the target template a call to the question. For example,
In the javascript tab:
function myCalculator() {
var data = [1, 2, 3];
...
}
In the header or footer part of the template:
<script>
myCalculator();
</script>
Or, you can use an element that you know to exist only in the target template to condition the execution of the script (you can add that element to the template). For exmple:
In the header or footer part of the target template add something like:
<div id="my-calculator-div"></div>
In the javascript tab:
if (document.getElementById("my-calculator-div")) {
var data = [1, 2, 3];
...
}
hth
Have you looked at Database_templates#Javascript_template for the basic idea? From there it is just a matter of what you want to do, googling a possible solution and implementing it in your activity. That's at least is how I go about that when I'm not writing to solution from scratch.