rendered paste body /*************************************************************/
/* Name : Anthony Alves */
/*************************************************************/
function checkForm()
{
var error_message = "";
var temp_error = new Array(2);
temp_error[0] = surname();
if(temp_error[0] != "")
{
error_message += temp_error[0] + "\n";
}
temp_error[1] = surname();
if(temp_error[1] != "")
{
error_message += temp_error[1] + "\n";
}
if(error_message.length != "")
{
error_message = pageHeader(error_message);
error_message = pageFooter(error_message);
error_window = window.open("", "errors", 'width=450, height=300');
error_window.document.write(error_message);
error_window.document.close();
return false;
}
else
return true;
}
function surname()
{
var field01 = document.getElementById('field01');
var name_len = field01.length;
if(field01.value == "")
return "Must have a surname.";
for(var i=0; i<name_len; i++)
{
if(field01.charCodeAt(i) < 65 || (field01.charCodeAt(i) > 90 && field01.charCodeAt(i) < 97) || field01.charCodeAt(i) > 122)
return "All characters in surname must be alphabetic.";
}
return "";
}
function pageHeader(content) {
content = '<?xml version="1.0"encoding="UTF-8" ?>\n';
content += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
content += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
content += ' <html xmlns="http://www.w3.org/1999/xhtml">\n';
content += ' <head>\n';
content += ' <title>form validation</title>\n';
content += ' </head>\n';
content += ' <body>\n';
content += ' <h3>Please correct the following and resubmit the form</h3>\n';
content += ' <ul>\n';
return content;
}
function pageFooter(content) {
content += ' </ul>\n';
content += ' </body>\n';
content += ' </html>\n';
return content;
}
int222_081b02@home2:~/public_html/assign3> vi myscript.js
int222_081b02@home2:~/public_html/assign3> vi myscript.js
int222_081b02@home2:~/public_html/assign3> vi myscript.js
int222_081b02@home2:~/public_html/assign3> vi myscript.js
int222_081b02@home2:~/public_html/assign3> cat myscript.js
/*************************************************************/
/* Name : Anthony Alves */
/*************************************************************/
function checkForm()
{
var error_message = "";
var temp_error = new Array(2);
temp_error[0] = surname();
if(temp_error[0] != "")
{
error_message += temp_error[0] + "\n";
}
temp_error[1] = surname();
if(temp_error[1] != "")
{
error_message += temp_error[1] + "\n";
}
if(error_message.length != "")
{
error_message = pageHeader(error_message);
error_message += temp_error[0];
error_message += temp_error[1];
error_message = pageFooter(error_message);
error_window = window.open("", "errors", 'width=450, height=300');
error_window.document.write(error_message);
error_window.document.close();
return false;
}
else
return true;
}
function surname()
{
var field01 = document.getElementById('field01');
var name_len = field01.length;
if(field01.value == "")
return "Must have a surname.";
for(var i=0; i<name_len; i++)
{
if(field01.charCodeAt(i) < 65 || (field01.charCodeAt(i) > 90 && field01.charCodeAt(i) < 97) || field01.charCodeAt(i) > 122)
return "All characters in surname must be alphabetic.";
}
return "";
}
function pageHeader(content) {
content = '<?xml version="1.0"encoding="UTF-8" ?>\n';
content += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
content += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
content += ' <html xmlns="http://www.w3.org/1999/xhtml">\n';
content += ' <head>\n';
content += ' <title>form validation</title>\n';
content += ' </head>\n';
content += ' <body>\n';
content += ' <h3>Please correct the following and resubmit the form</h3>\n';
content += ' <ul>\n';
return content;
}
function pageFooter(content) {
content += ' </ul>\n';
content += ' </body>\n';
content += ' </html>\n';
return content;
}