Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Monday, November 19, 2007

Run External Jscript in an External Jscript

My goal is to have an external js file loading a set of js files. In this case, for starters, just one subsequent external js, js2.js.



loader.html - to load all the subsequent js files.



<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>JsLoader</title>

<script src='js1.js' type='text/javascript' /></script>

</head>


<body>

<input type="button" onClick="f1()" value="Load" />


</body>

</html>



js1.js - External js file 1



function f1(){

var NewScript=document.createElement('script')

NewScript.src="js2.js"

document.body.appendChild(NewScript);

f2();

}



j2.js- External js file 2



function f2(){

alert('I told you I can get here!')

}





Files:
loader.html
js1.js
js2.js

Sunday, November 18, 2007

Run External Javascript on Webpage

Create a HTML file msgBox.html, without Importing External Js:


<HTML>

<HEAD>


<SCRIPT LANGUAGE="JavaScript">

function MsgBox (textstring) {

alert (textstring) }

</SCRIPT>


</HEAD>


<BODY>


<FORM>

<INPUT NAME="text1" TYPE=Text>

<INPUT NAME="submit" TYPE=Button VALUE="Show Me" onClick="MsgBox(form.text1.value)">

</FORM>


</BODY>

</HTML>


Create File msgBox.js with the code:


function MsgBox (textstring) {

alert (textstring) }

Change the html code to:




<HTML>

<HEAD>

<script src='msgBox.js' type='text/javascript' /></script>

</HEAD>

<BODY>

<FORM>

<INPUT NAME="text1" TYPE=Text>

<INPUT NAME="submit" TYPE=Button VALUE="Show Me" onClick="MsgBox(form.text1.value)">

</FORM>

</BODY>

</HTML>





Download

msgBox.html - html page holding the javascript

msgBox.js - js file to be imported






References:

http://www.webteacher.com/javascript/ch01.html