Ask Question

Ask Question

by Muhammad Raffi Ramadhan -
Number of replies: 14
Hey, i am clueless on how to add some javascript function on moodle when users start to attempt a quiz. so when users click the "start attempt" the quiz, i want to add some javascript code on their client side. is that possible?
if so what can you suggest i take a look for
Average of ratings: -
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Add your JavaScript code to the HTML of a "Text" block that you set to appear on the "Attempt quiz" page.
Average of ratings:Useful (1)
In reply to Dominique Bauer

Re: Ask Question

by Muhammad Raffi Ramadhan -
well, thanks for the insight. i did try to find where is the "attempt quiz" page. but i didn't find any kinds of html tag nor javascript tag. so i am not sure if i can just put it directly into it.
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Try something like this:

<script>
   alert("Hello!");
</script>

Can you have this simple script work?
Average of ratings:Useful (1)
In reply to Dominique Bauer

Re: Ask Question

by Muhammad Raffi Ramadhan -
i try to add it on attempt.php file
but i just got error placing that anywhere in the file
i am still learning on understanding the structure so it is still a long way to fully understand that
by any chance do you know the file on which i should edit, i mean like the file that represents the html of the page. because on the page "attempt.php" (not just this file) they are referencing to another file a lot. i don't even see a html tag on that file
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
You mentioned that you wanted to add client-side JavaScript code. Therefore, you don't want to edit PHP files but simply place your code in a 'Text' block so that it can manipulate the DOM, i.e., work on the client side.

If you want to work on the server side and edit PHP files, that's a different story.

It would help us help you if you could specify more precisely what you want to do.
Average of ratings:Useful (1)
In reply to Dominique Bauer

Re: Ask Question

by Muhammad Raffi Ramadhan -
i want to add some javascript function when quiz is being initialized by a student (quiz_accessrule) just like how secure_window(quiz_accessrule) do. so if a user attempt quiz, there will be some quiz access rule that applied (some javascript).
i'm sorry i didn't mentioned it clearly. so i am asking where is the javascript function can i write in my plugin. while seeing the secure_window access rule i didn't see any javascript file, i just see a referenced to it.
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
A person like Tim Hunt should be able to help you.
In reply to Dominique Bauer

Re: Ask Question

by Muhammad Raffi Ramadhan -
dear Dominique, thank you for your reply . is there any way i can reach him or something?
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Muhammad,

Tim Hunt is one of the best, if not the best Moodle senior software developer. I hope he will be able to help you.
Average of ratings:Useful (1)
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Tim tends to monitor Moodle.org discussions, especially when posts involve "quizzes." I will not try to speak for Tim, but your question seems to relate to wanting to modify core Moodle behavior. Tim tends to focus on managing core Moodle behavior, bugs and improvements, so don't be surprised if Tim doesn't jump in. Having said this, Tim seems to help with these kinds of questions when the answer is short. You might try to describe what feature you are trying to add via javascript.
Average of ratings:Useful (1)
In reply to Rick Jerz

Re: Ask Question

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators

She waited for some time without hearing anything more: at last came a rumbling of little cartwheels, and the sound of a good many voices all talking together: she made out the words: `Where's the other ladder?--Why, I hadn't to bring but one; Bill's got the other--Bill! fetch it here, lad!--Here, put 'em up at this corner--No, tie 'em together first--they don't reach half high enough yet--Oh! they'll do well enough; don't be particular-- Here, Bill! catch hold of this rope--Will the roof bear?--Mind that loose slate--Oh, it's coming down! Heads below!' (a loud crash)--`Now, who did that?--It was Bill, I fancy--Who's to go down the chimney?--Nay, I shan't! You do it!--That I won't, then!--Bill's to go down--Here, Bill! the master says you're to go down the chimney!'

`Oh! So Bill's got to come down the chimney, has he?' said Alice to herself. `Shy, they seem to put everything upon Bill! I wouldn't be in Bill's place for a good deal: this fireplace is narrow, to be sure; but I think I can kick a little!'

https://www.cs.cmu.edu/~rgs/alice-IV.html

smile

In reply to Rick Jerz

Re: Ask Question

by Muhammad Raffi Ramadhan -
dear Rick, thank you for the explanation.
I kinda wants to make a function to prevent student to minimize screen while taking quiz, so i already try to implement that in a really simple file, so apparently when students click the "Start attempt" the screen become fullscreen. and with that i'd make a fullscreen change event handler that will submit the quiz automatically. i still don't know if that's possible or not. hence why i'm asking here to get a bit more insight
In reply to Muhammad Raffi Ramadhan

Re: Ask Question

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators