[Contents]

jsEditor - Using the knowledge base

Aim: to demonstrate how to use the knowledge base

Start a new file. Type:

alert('My pet cat'.subString(3,6));

(The above code has an error, by the way.)

Select this code. choose JavaScript tags from the JS mode popup menu.

<SCRIPT LANGUAGE="JAVASCRIPT">

<!--//

alert('My pet cat'.subString(3,6));

//-->

</SCRIPT>

Press F9 or Preview.

JavaScript reports that 'this object does not support this property or method' and tells us the line number if 4.

Enter 4 in the line number box (next to the finger down symbol) and click the symbol or press return.

(As there isn't much code we can easily realise that the problem is on that line - but when you have 30 or 100 lines ... it is extremely useful). Note the line and character numbers at the bottom of the page - in case you need to find out exactly where the error occurred.

Choose Data from the main menu and type substring in the box and press return (or the button named 'Find in List')

On first click (or return) the subject 'substring method' is highlighted. On second click, nothing happens because there is no more information on substring. Try this after typing 'set' and you will find lots of entries! If you type something else in the box, the list will reset and start from the beginning again.

Back to the error message.

From this message we realise that JavaScript writes differently from us and it is NOT subString but substring!

Correct the writing and try the code again. The code works.

Click the JS mode button and choose Strings. As substring is there, we could have entered it as boilerplate and avoided all this hassle. But perhaps the intention is to illustrate how to use parts of the jsEditor! And every function, method, etc is not in the boilerplate. So on other occasions, we need to check our spelling.

While substring is selected in the Knowledge Base, click 'Copy Text' and paste the example code into the editor. Select it and add JavaScript tags. Then preview the code.

You have learned how to:

Next: How to create an array in seconds