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

No comments: