[Contents]

jsEditor - Wizards: Doc Write

Aim: to demonstrate how to use the doc write wizard

Select the following code and copy it

<HTML>

<SCRIPT LANGUAGE="JAVASCRIPT">

function MyFunction(){

alert("Hello");

}

</SCRIPT>

<BODY>

<H1>

My document.write example

</H1>

<P>

This is an example of an HTML file which we might want to write using document write.

<P>

It is also an easy way to make a string with HTML, etc. Doing this by hand, can be very difficult because of the various types of quotes used. And the frequent 'un-terminated string' messages. With the doc write wizard it is easy.

<P>

See <a href="#" onClick="MyFunction();return false">my alert</a>!

</BODY>

</HTML>

From the main menu, choose Wizards, and Doc Write Wizard. Clear the left hand box and paste the above code in it.

Keep the defaults and click OK. The Wizard will probably give you a message saying you are not allowed to use JavaScript here and if you do all sorts of terrible and dire  things will happen and they will not be its responsibility because it has warned you.

Ignore the warning and continue. Press OK.

The following code is generated:

<script language="JavaScript">

<!--//

function MyDocWriteFunction(){

mystring='';

mystring=mystring+"<HTML>"

mystring=mystring+"<SCRIPT LANGUAGE='JAVASCRIPT'>"

mystring=mystring+"function MyFunction(){"

mystring=mystring+"alert('Hello');"

mystring=mystring+"}"

mystring=mystring+"</SCRIPT>"

mystring=mystring+"<BODY>"

mystring=mystring+"<H1>"

mystring=mystring+"My document.write example"

mystring=mystring+"</H1>"

mystring=mystring+"<P>"

mystring=mystring+"This is an example of an HTML file which we might want to write using document write. "

mystring=mystring+"<P>"

mystring=mystring+"It is also an easy way to make a string with HTML, etc. Doing this by hand, can be very difficult because of the various types of quotes used. And the frequent 'unterminated string' messages. With the doc write wizard it is easy. "

mystring=mystring+"<P>"

mystring=mystring+"See <a href='#' onClick='MyFunction();return false'>my alert</a>! "

mystring=mystring+"</BODY>"

mystring=mystring+"</HTML>"

document.write(mystring)

}

//-->

</script>

You have created a string very easily even though there are different types of quote to handle. Doing this without the Wizard is not hard, but can be very tedious and frustrating. You can use the string created (mystring) for other purposes when you would delete the document.write(mystring) and edit other parts as necessary.

Click somewhere after the SCRIPT tags (after </SCRIPT>) and type:

"Write a new page"

Select this and choose from the main menu, Wizards and Wizard Function Link. Keep the defaults and click OK.

The following code is added:

<a href="#" onClick="MyDocWriteFunction();return false">Write a new page</a>

Press the Preview tab or F9 to preview the code and click on the link to view the alert.

What you have learned:

 

Note: The warning given is serious. JavaScript can sometimes (usually) cause problems when it is put in the Doc Write Wizard. Try to get this code to work when you put the <!--// etc tags in!

If you do, enter the line number in the box next to the 'finger down' symbol and press return. You will go the the line number indicated. This is only a demonstration of going to a line number. Do not expect an easy solution!

Next: Using the knowledge base