Client Side Scripting
Client Side Scripting
HTML stands for Hyper Text Markup Language The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox, Safari) is to read HTML documents and display them as web pages. Q: Write HTML code for creating different types of lists Ans: Unordered list <ul> <li>Item</li> <li>Item</li> </ul> Ordered list <ol> <li>First item</li> <li>Second item</li> </ol> Definition list <dl> <dt>Item 1</dt> <dd>Describe item 1</dd> <dt>Item 2</dt> <dd>Describe item 2</dd> </dl> Q: Write HTML code to create a table Ans: Tables <table border="1"> <tr> <th>table header</th> <th>table header</th> </tr> <tr> <td>table data</td> <td>table data</td> </tr> </table> Q: Write HTML code for creating Login form Ans: <html> <form method="post" action="login.php"> MailID:<input type="text" size=20 name='mailid' value="[email protected]"><br> Password:<input type="password" size=17 name='password'> <input type="submit" value="Login"> <form> </html>
Q: What is meant by CSS? Explain CSS Rule. Ans: CSS stands for Cascading Style Sheets
The id selector is used to specify a style for a single, unique element. The id selector uses the id attribute of the HTML element, and is defined with a "#". The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. The class selector uses the HTML class attribute, and is defined with a "." Q: What are the different ways of inserting style sheets in HTML? Explain with examples. Ans:There are three ways of inserting a style sheet: External style sheet Internal style sheet Inline style style.css in styles folder h1{background:red;font-style:italic} div{background:pink} p{background:green} ess.htm <html> <head> </head> <body> <link rel = "stylesheet" href = "styles\style.css" type="css"> <h1>CSS External style sheets example!</h1> <div> This is a text inside a div element. <p>This paragraph has its own background color.</p> We are still in the div element. </div> </body> </html>
<html> <head> <style> h1{background:gold;font-style:italic} p{background:green;} div{background:pink;} </style> </head> <body> <h1>Internal style sheet example</h1> <div> This is a text inside a div element. <p>This paragraph has its own background color.</p> We are still in the div element. </div> </body> </html> <h1 style="font-style:italic;backgroundcolor:yellow">Inline style sheet example</h1> <p style="color:red">Red para</p> JavaScript is a client side scripting Language. The lines between the <script> and </script> contain the JavaScript. If we put JavaScript code inside a function, we can call that function when an event occurs. External JavaScript files have the file extension .js JavaScript is case sensitive. "Everything" in JavaScript is an Object. If you assign a value to variable that has not yet been declared, the variable will automatically be declared as a GLOBAL variable. Exception handling in javascript can be done through try, catch and throw statements. The try statement lets you to test a block of code for errors. The catch statement lets you handle the error. The throw statement lets you create custom errors. A regular expression is an object that describes a pattern of characters. A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. DHTML (Dynamic HTML) = HTML+CSS+JavaScript+DOM A regular expression is an object that describes a pattern of characters. A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. Q: Write Javascript code to find biggest of two numbers. Ans: <script> var n1,n2; n1=window.prompt("Enter first number","0"); n2=window.prompt("Enter second number","0"); if(n1>n2) document.writeln(n1+" is greater than "+n2); else document.writeln(n2+" is greater than "+n1); </script>
Q: Write java script code to validate a form. Ans: <html> <head> <script> function validateForm() { var x=document.forms["myForm"]["fname"].value; if (x==null || x=="") { alert("First name must be filled out"); return false; } } </script> </head> <body> <form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post"> First name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> </body> </html> Q: Write javascript code to check whether cookies are enabled or not in your browser. Ans: <html> <body onload="checkCookies()"> <script> function checkCookies() { if (navigator.cookieEnabled==true) {alert("Cookies are enabled") } else {alert("Cookies are not enabled") } } </script> <p>An alert box should tell you if your browser has enabled cookies or not.</p> </body> </html>
Q: Write about Applets Ans: Applets are small Java Programs for internet applications An applet located on a distant computer can be down loaded via internet executed on a local computer using a java compatible Browser We can develop applets for doing everything from simple animated graphics to complex games Applet is a java program that can be embedded into HTML pages. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining. Applets are cross platform and can run on Windows, Mac OS and Linux platform Applets runs in a sandbox, so the user does not need to trust the code, Applets are supported by most web browsers Applets are cached in most web browsers, so will be quick to load when returning to a web page . Instead of writing a program that has a main() method as in the case of an application, applets are any class that subclasses the Applet class and override some of its methods.