Nice book written by Scott Duffy.
Few quotations i wanted to share from this book from the next 3 chapters(8-9-10)
1) Privacy and the Internet
HTML forms are commonly used to allow visitors to log in to a web site. Users must normally supply a valid user ID and password to the server before being allowed into the restricted areas of the site.
From a developer’s point of view, a text box should be used to request the user ID from the user. As an added level of security, a password box control should be used to request a user’s password. The password box replaces the characters typed in with asterisks, so that password becomes ********. This is done so that other individuals looking at the same computer monitor (from over the user’s shoulder, for instance) will not be able to read the password.You should know, however, that this is a very weak type of security. Unless the form data is encrypted using Secure Sockets Layer (SSL), typically using HTTPS protocol, the password will be sent over the Internet as plain text, which can be easily read by anyone along the path or by anyone with access to the web server’s activity logs.
2) Catch Events on Form Controls
Like the HTML form tag, form controls can also have programmable events. A program can define a JavaScript function or code that will be executed when a certain event occurs. For instance, JavaScript can detect when the mouse cursor passes over a control, when it has gained or lost focus, or when its value has changed.
Example:
<script>
function modifylayer() {
var lefield = document.getElementById("lastevent");
var ename = window.event.type;
lefield.innerHTML = ename + "<br><br> ";
}
</script>
<body>
<textarea name="samplefield" rows="10" cols="30" onmouseover="modifylayer()" onmouseout="modifylayer()" onchange="modifylayer()" onkeypress="modifylayer()">
Sample text
</textarea>
<div id="lastevent"></div>
</body>
3) An event handler is JavaScript code that is designed to run each time a particular event occurs. Of course, this means that your JavaScript code may execute dozens of times, or not at all, depending on the circumstances.
4) To cancel an event, you just need to make its event handler return false. Canceling a keydown or keypress event will cause the browser to ignore those keys. For example, if you wanted to restrict the types of characters entered into a form field, you could capture its keydown event and return false anytime a key is not in an acceptable range.
<script type="text/javascript" language="javascript">
function checkkey() {
var keycode = window.event.keyCode;
if (keycode < 48 || keycode > 57) {
return false;
} else {
return true;
}
}
</script>
<form action="#">
<input type="text" name="box1"
onkeydown="return checkkey()"><br>
</form>
5) Handle HTML Events
In this context, HTML events means any events that do not belong in the user interface, mouse, or
key event categories. Some HTML events are triggered directly by a user action, while others are
fired only as an indirect result of a user action.
Let’s take a quick look at what these events do.
a) load event :- The onload event handler is called when the HTML document finishes loading into the browser window. This event is commonly relied on to do any initialization required in the document. For instance, if form fields need to be preloaded with text, and that was not covered by the HTML code itself, it is best to wait until the document is fully loaded before initializing those fields.
b) unload event :- The unload event fires when a browser is leaving the current document.This happens when the browser window is being closed or the user has moved on to another document. The main purpose of this event is to perform cleanup tasks before the document closes.
The unload event is commonly used in some of the seedier web locations to provide final pop-up advertising before a user leaves a web site. This is generally considered bad etiquette. The unload event should be avoided unless absolutely necessary.
c) submit event :- The submit event occurs just before a form is submitted to a web server.
It is common to capture this event to perform edit checking before allowing a form submission to continue. Since this event can be canceled, JavaScript can stop the form from being processed if everything is not in order.
d) reset event :- The reset event occurs when the reset button on a form is clicked. The reset
button clears a form by resetting all the values back to their defaults. select event The select event occurs when the user selects text inside a text box or text area. Text can be selected by holding the left mouse button down while dragging across the text or by holding the SHIFT key down while using the arrow keys to move the cursor across the text.
e) change event :- The change event occurs when a control loses focus (the user tabs out of it) and its value has been altered. This way, in text boxes the change event does not fire for each and every keystroke when a user is entering a value but only when the user leaves the field. This same event fires on radio buttons, check boxes, and select lists in the same manner.
f) abort event :- The abort event occurs when the browser stops trying to load an image on the web page. This can occur when the user hits the browser’s Stop button or clicks
a link to go to another page. In my experience, this event is rarely used.
g) error event :- The error event occurs when an error happens while the web page is being
loaded. This could be an error specific to a particular object (such as a Java applet’s failing
to load) or a run-time error caused by poorly written JavaScript code. This is another event
that is rarely captured in most web pages.
h) resize event :- The resize event fires when an object is being resized—for instance, if a browser window has been resized by the user, or a frame. There may be times when you would like to be able to resize the individual controls inside the window based on the available space, although capturing this event is still rare.
i) scroll event For web objects that scroll, such as the browser window or a text area form control, the scroll event is fired anytime the object’s scroll bar is changed. This can be done using the mouse to move the scroll bar manually, by using arrow keys, or by other means.
6) Define and Name Frames in a Frameset
Now that you understand how simple and complex framesets are created using the
tag, we should take a brief look at how the frames themselves are defined. Individual frames are defined using the frame tag. The frame tag has the following attributes:
<frameset>
a) id Documentwide unique ID
b) class List of associated CSS classes
c) style Inline CSS style commands
d) title Advisory title
e) longdesc Link to a longer description of the frame
f) name Internal name of the frame
g) src URI to the HTML document
h) frameborder Visibility of the frame borders
i) marginwidth Amount of space, in pixels, between the vertical border (or window frame) and the HTML contents
j) marginheight Amount of space, in pixels, between the horizontal border (or window frame) and the k) HTML contents
m) noresize Controls whether the user can resize the frame
n) scrolling Visibility of the scroll bar
About the Author
Scott Duffy has been providing IT consulting services to medium- and large-sized businesses and government organizations for more than six years. Before embarking on a career as a consultant, Scott worked at two of the largest corporations in Canada as a software developer.His 12 years of professional experience cover a wide range of platforms and technologies, including programming in mainframe, client-server, and web-based application environments. He is actively involved in every stage of the software development process, including team
management.
When he’s not designing software applications for clients, Scott keeps himself busy with his writing projects. He is currently working on his next book for McGraw-Hill/Osborne, a study guide for the Microsoft MCSD 70-300 exam.
To contact Scott to discuss your organization’s business needs, or about any other matter,please e-mail him at scott.duffy@mydemos.com or visit his web site at http://www.mydemos.com.
Hope you enjoy reading this book.
No comments:
Post a Comment