General developer forum

 
 
Picture of Raphael Goldman
how to implement javascript in the edit quiz page
 

Hello,

I just need an example when someone start entering text in the title then to pop-up an hello alert,

How do i do that?

Thanks

 
Average of ratings: -
Andrew Normore
Re: how to implement javascript in the edit quiz page
 

Go to the /mod/quiz/form_edit.php file

That's a good place to start. I'd include a JS file within that module, and have it listen for keypresses on your form element "title".

 
Average of ratings: -
Picture of Raphael Goldman
תשובה ל: Re: how to implement javascript in the edit quiz page
 

Thanks,

Can you please show me an example how to add the js file?

and just a simple example of an alert when keydown has been pressed on the title box?

Thanks a lot,

Raphael

 
Average of ratings: -
Picture of Alin Ungureanu
Re: תשובה ל: Re: how to implement javascript in the edit quiz page
 

Hi Raphael,

To add a "js_file.js", you need the following line in the Head of your Html code:

<script type="text/javascript" src="path_to_file/js_file.js"></script>

Alin

 
Average of ratings: -
Picture of Raphael Goldman
תשובה ל: Re: תשובה ל: Re: how to implement javascript in the edit quiz page
 

Thanks,

How can I reffer to a form element?

What is the id or class?

 

 
Average of ratings: -
Picture of Alin Ungureanu
Re: תשובה ל: Re: תשובה ל: Re: how to implement javascript in the edit quiz page
 

Hi Raphael,

var my_form =

document.forms[0]; or any other id

var elem = my_form.elements[0];

or

var my_form_elem =

document.getElementById("form_element_id");

Note that the "elem" or "my_form_elem" are objects, not strings.

You can take their value by

var str = elem.value;

Alin

 
Average of ratings: -
Picture of Alin Ungureanu
Re: תשובה ל: Re: תשובה ל: Re: how to implement javascript in the edit quiz page
 

Sorry, missed the second question.

The id and class are selectors. You can reffer a certain div or span or other html divisions for visual effect ( with css) or functional effect ( javascript, jquery...).

Alin

 
Average of ratings: -
Picture of Raphael Goldman
תשובה ל: Re: תשובה ל: Re: תשובה ל: Re: how to implement javascript in the edit quiz page
 

Thanks

I will try it

 
Average of ratings: -