Intro to Javascript
Author: Bill Trikojus
![]() |
|
![]() |
|
![]() |
|
![]() |
|
|
There's lots of other things you can do in Javascript and you will see some of these in this tute. Javascript uses a dot syntax so if you've done any actionscript or PHP then it should look familiar to you. Like Flash, Javascript has built in objects such as 'window' that have different methods and properties you can call and set. Generally speaking you will put a javascript function into the head of your html page <title>My page has javascript...yay</title> <script type="text/javascript"> function alertTheUser(){ alert("Hi I'm a Javascript alert and you will learn to love me"); } </script> </head>
<input type="button" value="I know you want to click me" onClick='alertTheUser()'> </body> |
|
![]() |
|
|
alert("Hi I'm a Javascript alert and you clicked on the button called '"+whoWasClicked.name+"'"); } and then changed the line that makes the button to <input type="button" name="the cool button" value="I know you want to click me" onClick='alertTheUser2(this)'>You would end up with whoWasClicked.value="You shouldn't have done that"; }
(here's one I made for you) |
|
![]() |
|
|
Name:<input type='input' name='userName'><br> Comments:<textarea name="userComment"></textarea><br> <input type='submit' value='Submit this form now!' > </form> Paste that inside the body of your html page and then add this javascript function to the head of your HTML page (btw all javascript functions in the head must go inside the <script type='text/javascript'>and </script>tags) function validate(){theForm=document.someForm; ok=true; if(theForm.userName.value==''){ ok=false; theForm.userName.value="don't have a name?"; theForm.userName.focus(); return false; } if(theForm.userComment.value==''){ ok=false; theForm.userComment.value="the quiet type hey?"; theForm.userComment.focus(); return false; } if(ok){ theForm.userName.value="YAY"; theForm.userComment.value="the form was OK"; theForm.userComment.focus(); //this would normally be return true return false; } }
|
|
![]() |
|
|
{ window.open(url,"my_new_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width="+w+", height="+h); }
{ window.open(url,"my_new_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars="+sbars+", resizable="+resize+, width="+w+", height="+h); }
I am some plain text<br> <script type="text/javascript"> var time = new Date(); if(time.getHours()>12){ document.write('Good afternoon'); }else{ document.write('Good morning'); } document.write('<br>'); </script> I am more plain text </body> or as a body tag attribute such as <body onLoad="javascript:openwindow('http://swin.edu.au',200,400,'no','yes')">OK that's enough to get you started. For heaps more info on Javascript go here. |
|
Share
Like this? Click a link below to share it...Subscribe and Download

Post a comment
Garbage posts and SPAM will be deleted.




