DOC PREVIEW
Penn CIT 597 - JavaScript Examples

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

JavaScript ExamplesGetting the dateGetting and formatting the dateGetting a random numberGetting a random integerDisplaying an alert boxTelling what happenedTelling what happened (Button)The EndJan 14, 2019JavaScript ExamplesGetting the date<script type="text/javascript"> var d = new Date() document.write(d.getDate() + "/") document.write((d.getMonth() + 1) + "/") document.write(d.getFullYear()) </script> 27/10/2003Getting and formatting the date<script type="text/javascript"> var d=new Date() var weekday=new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday") var monthname=new Array("Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") document.write(weekday[d.getDay()] + ", ") document.write(monthname[d.getMonth()] + " " + d.getDate() + ", ") document.write(d.getFullYear())</script>Monday, Oct 27, 2003Getting a random numberThe following code gets a random floating-point number between 0 and 1:<script type="text/javascript"> document.write(Math.random())</script>0.728762788388911Getting a random integerThe following code gets a random integer between 1 and 10:<script type="text/javascript"> var max = 10; number=Math.random()*max + 1; document.write(Math.floor(number));</script>5Displaying an alert boxThe following code displays an alert box when a button is clicked:<form> // Buttons can only occur within forms <input type="button" name="Submit" value="Alert!“ onclick="alert('Oh oh, something happened!');"></form>Telling what happenedIn my Concise JavaScript, part 2, I have code that shows what events occur when the user takes various actionsIn the <head> of the HTML page I define:<script> <!-- function tell(a, b) { document.forms[0].result.value+="\n"+a+": " + b; }//--></script> For each form element, I have a handler for every (plausible) eventTelling what happened (Button)<input type="button" name="plainButton" value="Plain Button“onMouseDown="tell(this.name, 'onmousedown');" onMouseUp="tell(this.name, 'onmouseup');" onClick="tell(this.name,'onclick');" onDblClick="tell(this.name,'ondblclick');“onFocus="tell(this.name, 'onfocus');“onBlur="tell(this.name, 'onblur');“onMouseOver="tell(this.name, 'onmouseover');" onMouseOut="tell(this.name, 'onmouseout');" onChange="tell(this.name, 'onchange');“onKeyPress="tell(this.name, 'onkeypress');“onKeyDown="tell(this.name, 'onkeydown');“onKeyUp="tell(this.name, 'onkeyup');“onSelect="tell(this.name, 'onselect');“onReset="tell(this.name, 'onreset');“>The


View Full Document

Penn CIT 597 - JavaScript Examples

Documents in this Course
DOM

DOM

21 pages

More DOM

More DOM

11 pages

Rails

Rails

33 pages

DOM

DOM

21 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

Rake

Rake

12 pages

Ruby

Ruby

58 pages

DOM

DOM

21 pages

Tomcat

Tomcat

16 pages

DOM

DOM

21 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Html

Html

27 pages

DOM

DOM

22 pages

RELAX NG

RELAX NG

30 pages

Servlets

Servlets

28 pages

XHTML

XHTML

13 pages

DOM

DOM

21 pages

DOM

DOM

21 pages

Servlets

Servlets

26 pages

More CSS

More CSS

18 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Load more
Download JavaScript Examples
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view JavaScript Examples and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view JavaScript Examples 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?