Web Technologies - Lab 2: Mohamed Sellami, ISEP
Web Technologies - Lab 2: Mohamed Sellami, ISEP
Contents
1 HTML, CSS and JavaScript 1
1.1 Part 1: CSS style sheet . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Part 2: Basic form validation (JavaScript) . . . . . . . . . . . 3
1.3 Part 3: Dynamically change the style and the DOM . . . . . 3
4 Autocopmlete 5
4.1 Using the jQuery UI API and a predefined cities list . . . . . 5
4.2 Using AJAX and a cities API . . . . . . . . . . . . . . . . . . 5
1
<h1>Index Page of the MVC Application (Lab1)</h1>
<form>
First Name: <input type="text" name="fName" /><br>
Last Name: <input type="text" name="lName" /><br>
Birth Day: <input type="text" name="bDay" /><br>
Sex :<input type="radio" name="sex" value="male" checked>Male
<input type="radio" name="sex" value="female">Female
<br><input type="submit" />
</form></body></html>
• Displays <label> element as block element using the CSS display prop-
erty (display:block;)
2
Figure 2: Output of the sample HTML form whith a CSS style sheet
• changes the color of the fieldset border and its legend to blue if female
is clicked, red if male is clicked.
• changes the border color of the inputs (text and button) to blue if
female is clicked, red if male is clicked.
3
• changes “Index Page of the MVC Application (Lab1)” in the <h1>
element into “Hello Madam” if female is clicked and into “Hello Sir” if
male is clicked.
<ol>
<li><input type=button value=’Change <h1> Title’ onClick=’f1();’>
: Changes the text in <h1>.
<li><input type=button value=’Change the text in <div>’ onClick=’f2();’>
: Changes the text in <div>.
<li><input type=button value=’Insert some text after the text in <div>’
onClick=’f3();’>
: Insert some text after the text in <div>.
<li><input type=button value=’Change the <title>’ onClick=’f4();’>
: Changes the title (<title>) of the Web page.
<li><input type=button value=’Toggle’ onClick=’f5();’>
: toggles between hide() and show() the text in <div>.
</ol>
</body>
</html>
4
• Use jQuery to create a file myJqueryScript.js defining the functions
f1(),f2(),f3(),f4() and f5().
1. Create an HTML page with a simple form containing two text input
elements (login and password) and a submit button.
2. When clicking on the button, ask the server using AJAX with
jQuery, whether or not the <login,password> are correct. To en-
sure this, create a Java Servlet on the server side that will check the
<login,password> combination: returns 1 if they are correct (<lo-
gin=”abc”,password=”123”>), 0 if not.
Hint:
• to stop the default action of the submit button click event, use the
method preventDefault. Details at: http://api.jquery.com/event.preventdefault/
• Update your code to display the result in the HTML page instead of
an alert box.
4 Autocopmlete
4.1 Using the jQuery UI API and a predefined cities list
Create a simple HTML page with one input field to get a city name. Use the
jQuery UI autocomplete function (see http://jqueryui.com/autocomplete/)
to add an auto-complete functionnality to this input element.