Javascript

Javascript

by Ishan Anders -
Number of replies: 2

Hi,

after playing the whole afternoon with Javascript templates on Moodle 2.4.x i ask for a solution to check the form with Javascript Code.

Any examples how to check if a box is checked or e textfield has input?

Ishan

Average of ratings: -
In reply to Ishan Anders

Re: Javascript

by Paul Young -

<script type="text/javascript"> 
var numbers = /^[0-9]+$/;
var sid=document.getElementById('field_36');
if (sid.value!="") document.getElementById('field_36').readOnly = true;
function checkIt() {
if (sid.value!="" && !(sid.value.match(numbers))) {
alert('Only numbers are allowed for Student ID');
sid.value='';
}
}
 sid.onblur=checkIt;
}
</script>

In reply to Paul Young

Re: Javascript

by Ishan Anders -

Paul, thank you for the snippet.

But, if I use the code inside the Database activity as a template it didn't work.

Where should I integrate the snippet?

Sorry, I'm a newbee here.