Web topic 21 pass info via javascript

478 views

Published on

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
478
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Web topic 21 pass info via javascript

  1. 1. Web Authoring Topic 21 –Passing Information via Javascript
  2. 2. ObjectivesStudents should able to:1 Pass information via web forms usingthe submit button.2. Identify and use the various JavaScript features: • Variables. • Custom and Build-in Functions • alert() • prompt()
  3. 3. What is Javascript?JavaScript is a Web based programminglanguage. It can be used to createdynamic Web pages.A dynamic Web page changes itsappearance or the content depending onthe user input or the time.
  4. 4. Writing JavascriptA JavaScript program can be embeddedinto our HTML code.<HEAD> <TITLE>My JavaScript page</TITLE> <SCRIPT LANGUAGE= “text/JavaScript”> </SCRIPT></HEAD>
  5. 5. Writing JavascriptSome points to note about when writingJavascript.All JavaScript commands should come inbetween the <SCRIPT> and </SCRIPT>tagsAll JavaScript commands should befollowed by a semicolon (;)
  6. 6. Using AlertALERT commands are messages, whichpop up in a new small window.They automatically get closed when theuser clicks OK button.Syntax of the ALERT command: <SCRIPT language = “text/JavaScript”> alert(“Hello world!”); </SCRIPT>
  7. 7. Using variableWe can use variables in JavaScript likeother programming languagesUse the var keyword to declare variables. var secsPerMin = 60;Variables must start with either a letter orthe underscore character.Variable names are case-sensitive.
  8. 8. Using prompt commandThe PROMPT command is used to getinformation from the user.Sample code: var a = prompt(“What is your name?”); var b = “Good Morning!” + a; alert (b);
  9. 9. Using math operationsWe can use MATH operations to docalculations on the variables.Sample code:var secsPerHour = 0;secsPerHour = 24 * 60 * 60;alert (“The number of seconds in an year =” + secsPerHour);
  10. 10. Displaying TextIf we want to display text on the Webpage, we can use the followingcommand: document.write(“The number ofseconds in an year=” +secs_per_year);
  11. 11. Date object<SCRIPT LANGUAGE=”JavaScript”> var todayDate = new Date(); document.write("Todays Date is ") document.write(todayDate.getDate()); document.write(todayDate.getMonth()); document.write(todayDate.getYear());</SCRIPT>
  12. 12. Swapping ImagesUsing JavaScript you can change theimages when you place the mouse overit.This feature can be used to changebutton images, decorate images and tohighlight the links.

×