Hope this helps someone
I have a quiz and I wanted to show at the end of a question if the student got it right (green shooting start) or wrong (red X), So I wanted a screen (Mem Form) to open for a second then automatically close.
If you try to run javascript you will soon find controls are referenced by their ID
and I wanted to press the Cancel Button, but every time the form is generated the random ID is different. So I used the ClassName to find the Cancel Button as it is known as "nt-cancel-button"
So on tbe form which just has a red or green image there is a cancel button. On the form you go to the XHtml tab and insert the code below here - I used location = After </Form> so the following gets inserted under the main form.
This locates an element on the document (page) by the class name "nt-cancel-button" and finds the random ID assigned to it that pulls back a zero based list, so I want element zero the first cancel button it finds.
Then as a debug step this throws up a message box with the ID in it (Alert) so you can test that its working OK. When you are happy delete the Alert line.
Now I have the ID I can set a timer (in mSecs) to click the Cancel button.
So you answer a quiz question and press submit, the server side code figures if thats right or wrong, and opens a good form or a bad form that closes by itself after 2 seconds (2000 mSecs)
-------------------------------------------------------------------[ XHtml ]---
<script>
<!--
var xId = document.getElementsByClassName("nt-cancel-button")[0];
alert( xId.id );
setInterval(function ()
{document.getElementById(xId.id).click();}, 2000);
-->
</script>