|
home—lects—exams—hws
D2L—breeze (snow day)
Due: 2012.Nov.16, 14:00 (will be accepted through Nov.26 23:59).
We will further improve on hw03—Server side validation's .W.o.W. page by adding client-side validation, and making the form a sticky form.
Include all the same input-validation mentioned on hw03, but do the validation client-side as well, as sensible1
Note:(A hw03-soln and your hw03 grades will be ready in the next couple of days — Nov.12)If the input field fails validation, dynamically modify the html page to insert (or remove/zero-out) an error message. (Recall lect06a-js—case study: refactoring javascript Use css to control the style of the error message.)
The recommended way of reporting client-side verification errors:
If you have a field (say, “
Then, you will have a javascript function
check if a node
note that
var somePara = document.getElementById("my-favorite-para"); somePara.style.color = "blue"; somePara.innerHTML += "<em>watch out, we're at the end!</em>" |
Include two check-boxes: one for “do not actually submit (even if the form info all validates)”, and one for “submit form even if validation fails”. (These aren't usual end-user options; we include them just so that we can still test our client-side validation and stickiness.)
Since these two options are mutually-exclusive, when a user selects one
then
the other checkbox
should be disabled456.
When one of those boxes becomes unchecked,
make sure the other checkbox is un-disabled.
(Hint: set the other checkbox's
Make your page look neat and professional! You are encouraged to make your javascript code as similar as possible as the php-validation code, including wrapper functions to abstract away the differences.
1
For example, make sure the name has the same restrictions on length/characters
as the server-side validation.
But you don't need to validate that the drop-down menu's choice
is one of the legal options, because that's already
enforced by the drop-down itself.
(Similarly, the length of a field might well be enforced just
through the
2
There is, oddly, no standard js/DOM function “
/** Insert a node into the DOM after the referenceNode. * (Complements javascript's existing 'insertBefore'.) * @param (node) referenceNode -- the node after which the new node will be added. * @param (node) newNode -- the new DOM node to add. * @return void * @author lobo235, at http://www.netlobo.com/javascript-insertafter.html * @version 2007.Nov.07 */ function insertAfter( referenceNode, newNode ) { referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling ); } |
3 True, if they came from the form and we had client-side error checking on, then theoretically there could be no errors server-side. However, we'll deal later with some validation that might only happen server-side, such as looking up login info in a database. In these cases, it's important that the form be sticky. ↩
4
You disable an input field by
setting its attribute
5 We saw how to set the attribute of a DOM node using javascript; that is similar to how we toggled the “display” attribute of paragraphs, in lect06a-js.html. ↩
6 Usually, radio-buttons are used for mutually exclusive options, though in this case you'd need three. However, for this hw you are required to use checkboxes that are dynamically disabled, to learn that skill. ↩
7the function to show-source a file is one of the few exceptions ↩
home—lects—exams—hws
D2L—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2012.Nov.12 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |