Embed presentation
Downloaded 22 times

























![WEB PROGRAMMING UNIT-II NOTES: PREPARED BY BHAVSINGH MALOTHJavascript - BooleanJavascript - MathJavascript - Date:The Date object is a datatype built into the JavaScript language. Date objects are created with thenew Date( ) as shown below.SYNTAX:Here are different variant of Date() constructor:newnewnewnewDate( )Date(milliseconds)Date(datestring)Date(year,month,date[,hour,minute,second,millisecond ])Note: Paramters in the brackets are always optionalHere is the description of the parameters:No Argument: With no arguments, the Date( ) constructor creates a Date object set tothe current date and time.milliseconds: When one numeric argument is passed, it is taken as the internal numericrepresentation of the date in milliseconds, as returned by the getTime( ) method. Forexample, passing the argument 5000 creates a date that represents five seconds pastmidnight on 1/1/70.datestring:When one string argument is passed, it is a string representation of a date, inthe format accepted by the Date.parse( ) method.7 agruments: To use the last form of constructor given above, Here is the description ofeach argument:1. year: Integer value representing the year. For compatibility (in order to avoid theY2K problem), you should always specify the year in full; use 1998, rather than98.2. month: Integer value representing the month, beginning with 0 for January to 11for December.3. date: Integer value representing the day of the month.4. hour: Integer value representing the hour of the day (24-hour scale).5. minute: Integer value representing the minute segment of a time reading.6. second: Integer value representing the second segment of a time reading.7. millisecond: Integer value representing the millisecond segment of a timereading.DATE PROPERTIES:26](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fwebprogrammingunit-ii-131125230359-phpapp02%2f75%2fWeb-programming-UNIT-II-by-Bhavsingh-Maloth-26-2048.jpg&f=jpg&w=240)





![WEB PROGRAMMING UNIT-II NOTES: PREPARED BY BHAVSINGH MALOTHvar d = new Date()var weekday=newArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")document.write("Today is " + weekday[d.getDay()])</script></body></html>Display full dateHow to write a complete date with the name of the day and the name of the month.<html><body><script type="text/javascript">var d = new Date()var weekday=newArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")var monthname=newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")document.write(weekday[d.getDay()] + " ")document.write(d.getDate() + ". ")document.write(monthname[d.getMonth()] + " ")document.write(d.getFullYear())</script></body></html>Display timeHow to display the time on your pages. Note that this script is similar to the Time exampleabove, only this script writes the time in an input field. And it continues writing the time onetime per second.<html><body><script type="text/javascript">var timer = nullfunction stop(){clearTimeout(timer)}function start(){var time = new Date()32](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fwebprogrammingunit-ii-131125230359-phpapp02%2f75%2fWeb-programming-UNIT-II-by-Bhavsingh-Maloth-32-2048.jpg&f=jpg&w=240)
![WEB PROGRAMMING UNIT-II NOTES: PREPARED BY BHAVSINGH MALOTHvar hours = time.getHours()minutes=((minutes < 10) ? "0" : "") + minutesvar seconds = time.getSeconds()seconds=((seconds < 10) ? "0" : "") + secondsvar clock = hours + ":" + minutes + ":" + secondsdocument.forms[0].display.value = clocktimer = setTimeout("start()",1000)}</script></body></html>JAVASCRIPT - THE STRING OBJECT:SYNTAX:Creating a String object:var val = new String(string);The string parameter is series of characters that has been properly encoded.STRING PROPERTIES:Here is a list of each property and their description.PropertyDescriptionconstructorReturns a reference to the String function that created the object.lengthReturns the length of the string.prototypeThe prototype property allows you to add properties and methods to an object.EXAMPLE: STRING LENGTH33](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fwebprogrammingunit-ii-131125230359-phpapp02%2f75%2fWeb-programming-UNIT-II-by-Bhavsingh-Maloth-33-2048.jpg&f=jpg&w=240)



















This document provides notes on web programming unit 2 prepared by Bhavsingh Maloth. It discusses the history and objectives of JavaScript, defining it as a scripting language used to add interactivity to HTML pages. JavaScript can be divided into core, client-side, and server-side components. Core JavaScript is the basis of the language, while client-side JavaScript supports browser controls and user interactions. Server-side JavaScript makes the language useful on web servers. The document also provides examples of how to write text, insert scripts, and use variables in JavaScript.

























![WEB PROGRAMMING UNIT-II NOTES: PREPARED BY BHAVSINGH MALOTHJavascript - BooleanJavascript - MathJavascript - Date:The Date object is a datatype built into the JavaScript language. Date objects are created with thenew Date( ) as shown below.SYNTAX:Here are different variant of Date() constructor:newnewnewnewDate( )Date(milliseconds)Date(datestring)Date(year,month,date[,hour,minute,second,millisecond ])Note: Paramters in the brackets are always optionalHere is the description of the parameters:No Argument: With no arguments, the Date( ) constructor creates a Date object set tothe current date and time.milliseconds: When one numeric argument is passed, it is taken as the internal numericrepresentation of the date in milliseconds, as returned by the getTime( ) method. Forexample, passing the argument 5000 creates a date that represents five seconds pastmidnight on 1/1/70.datestring:When one string argument is passed, it is a string representation of a date, inthe format accepted by the Date.parse( ) method.7 agruments: To use the last form of constructor given above, Here is the description ofeach argument:1. year: Integer value representing the year. For compatibility (in order to avoid theY2K problem), you should always specify the year in full; use 1998, rather than98.2. month: Integer value representing the month, beginning with 0 for January to 11for December.3. date: Integer value representing the day of the month.4. hour: Integer value representing the hour of the day (24-hour scale).5. minute: Integer value representing the minute segment of a time reading.6. second: Integer value representing the second segment of a time reading.7. millisecond: Integer value representing the millisecond segment of a timereading.DATE PROPERTIES:26](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fwebprogrammingunit-ii-131125230359-phpapp02%2f75%2fWeb-programming-UNIT-II-by-Bhavsingh-Maloth-26-2048.jpg&f=jpg&w=240)





![WEB PROGRAMMING UNIT-II NOTES: PREPARED BY BHAVSINGH MALOTHvar d = new Date()var weekday=newArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")document.write("Today is " + weekday[d.getDay()])</script></body></html>Display full dateHow to write a complete date with the name of the day and the name of the month.<html><body><script type="text/javascript">var d = new Date()var weekday=newArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")var monthname=newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")document.write(weekday[d.getDay()] + " ")document.write(d.getDate() + ". ")document.write(monthname[d.getMonth()] + " ")document.write(d.getFullYear())</script></body></html>Display timeHow to display the time on your pages. Note that this script is similar to the Time exampleabove, only this script writes the time in an input field. And it continues writing the time onetime per second.<html><body><script type="text/javascript">var timer = nullfunction stop(){clearTimeout(timer)}function start(){var time = new Date()32](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fwebprogrammingunit-ii-131125230359-phpapp02%2f75%2fWeb-programming-UNIT-II-by-Bhavsingh-Maloth-32-2048.jpg&f=jpg&w=240)
![WEB PROGRAMMING UNIT-II NOTES: PREPARED BY BHAVSINGH MALOTHvar hours = time.getHours()minutes=((minutes < 10) ? "0" : "") + minutesvar seconds = time.getSeconds()seconds=((seconds < 10) ? "0" : "") + secondsvar clock = hours + ":" + minutes + ":" + secondsdocument.forms[0].display.value = clocktimer = setTimeout("start()",1000)}</script></body></html>JAVASCRIPT - THE STRING OBJECT:SYNTAX:Creating a String object:var val = new String(string);The string parameter is series of characters that has been properly encoded.STRING PROPERTIES:Here is a list of each property and their description.PropertyDescriptionconstructorReturns a reference to the String function that created the object.lengthReturns the length of the string.prototypeThe prototype property allows you to add properties and methods to an object.EXAMPLE: STRING LENGTH33](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fwebprogrammingunit-ii-131125230359-phpapp02%2f75%2fWeb-programming-UNIT-II-by-Bhavsingh-Maloth-33-2048.jpg&f=jpg&w=240)

















