80 likes | 296 Views
JavaScript. Client Side Processing. JavaScript. JavaScript runs in the browser (the client) JavaScript programs do not need to access the server. JavaScript programs can change the content and the appearance of a page. Using onload.
E N D
JavaScript Client Side Processing
Lecture 7: JavaScript JavaScript • JavaScript runs in the browser (the client) • JavaScript programs do not need to access the server. • JavaScript programs can change the content and the appearance of a page.
Using onload • The JavaScript onload is different to the C# Page_Load. It happens at the client: • Include this line in the <source> view of your page: <body onload="ol()"> • It will make the page run the JavaScript function ol Lecture 7: JavaScript
backgroundColor • You can set the background-color most elements: function ol(){ document.body.style.backgroundColor="red"; } Lecture 7: JavaScript
setInterval • You can use setInterval to make a function happen regularly. • Usually you call setInterval in onload function ol(){ setInterval(flipText,1000); } Lecture 7: JavaScript
getElementById • If an HTML element has an ID set you can find it and change it from JavaScript: var lbl = document.getElementById("Label1"); lbl.innerHTML = "Andrew was here"; Lecture 7: JavaScript
ToolTip and title • The ToolTip property in Visual Studio can be used to “hide” information that you show later. • You can swap innerHTML and title: var lbl = document.getElementById("Label1"); var tmp = lbl.innerHTML; lbl.innerHTML = lbl.title; lbl.title = tmp; Lecture 7: JavaScript
Summary • JavaScript is different to C# • Many things are similar. • JavaScript runs at the client, C# runs at the server. • It can be difficult to debug JavaScript Lecture 7: JavaScript