Unable to reedit a javascript in HTML editor

Unable to reedit a javascript in HTML editor

by FUTTERSACK Michel -
Number of replies: 2

I have enabled trustedtext in the Site rules, because i want to add javascripts in my webpages thanks the MOODLE's HTML editor

1) i typed the following code :

<script language="JavaScript">
function message() {
alert('ok');
}
</script>
<input type='button' value='Click me' onclick='message()'>

then i saved it and run it : it's OK

2) then i wanted modify this web page : the code returned from the DB was :

<script language="JavaScript">&amp;#010;function message() {&amp;#010;alert('ok');&amp;#010;} &amp;#010;</script> <input type="button" onclick="function onclick(event) { message(); }" value="Click me" />

I see the following error in the Firefox's Error console :

http://localhost/course/modedit.php?update=13&return=1

&#010;function message() {&#010;alert('ok');#010}

And of course if i try to launch the web page, i got a second error in the FireFox's Console

 

So, i understood ther is a problem with my LineFeeds converted by a PHP script in HTML entities. Then i deleted the LineFeeds

3) I typed the following code with no blanks :

<script language="JavaScript">function message(){alert('ok');}</script>
<input type='button' value='Click me' onclick='message()'>

This code worked and after recalling the HTML editor the code returned was :

<script language="JavaScript">function message(){alert('ok');}</script> <input type="button" onclick="function onclick(event) { message(); }" value="Click me" />

and i had no error in the Console

But after having saved the ressource, the script didn't work any more !!!!

4) i recall the editor . The code is now :

<script language="JavaScript">function message(){alert('ok');}</script> <input type="button" value="Click me" onclick="function onclick(event) { function onclick(event) { message(); } }" />

So my question is :

If i want to add javascript in a web page thanks to the MOODLE's HTML editor, is it forbitten to reopen this code in this editor ?????

 

Thanks in adance for your help

Average of ratings: -
In reply to FUTTERSACK Michel

Re: Unable to reedit a javascript in HTML editor

by Mauno Korpelainen -

This is one of the oldest HTMLArea bugs http://tracker.moodle.org/browse/MDL-9963

You can add and edit those javascripts if you disable editor from your user profile (When editing text - Use standard web forms) - otherwise HTMLArea will mess up your code - and after changes you can enable editor again from your profile.

Average of ratings: Useful (2)
In reply to FUTTERSACK Michel

Re: Unable to reedit a javascript in HTML editor

by FUTTERSACK Michel -

Many Thanks Mauno

You have fixed my problem

My conclusion is : if i need to edit/debug web pages with javascripts, the better way is to use an external HTML editor and after paste the code in the MOODLE HTML editor with the "standard web forms" option

Average of ratings: Useful (1)