...

View Full Version : Function Validation



sunzini
06-10-2004, 04:49 PM
Hi, this is my function which im trying to validate from a form to check if the input box's are empty or not. Does anybody know what im doing wrong?. Also how can i call this function(button) from an external file. any suggestions appreciated.




function process(form) {
//do the date
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

var num1 = document.story.one.value;
var num2 = document.story.two.value;
var num3 = document.story.three.value;
var num4 = document.story.four.value;
var num5 = document.story.five.value;
var num6 = document.story.six.value;
var num7 = document.story.seven.value;
var num8 = document.story.eight.value;
var num9 = document.story.nine.value;
var num10 = document.story.ten.value;

if (document.story.one.value == ""){
alert ("Please give a name, e.g John, Peter...");
document.story.one.focus();
return false;
}
if (num2 == ""){
alert ("Please give a place, e.g garden, park...");
document.story.two.focus();
return false;}

if (num3 == ""){
alert ("Please enter a feeling, e.g tired, exausted... ");
document.story.three.focus();
return false;}

if (num4 == ""){
alert ("Please enter an exercise, e.g sowing, planting... ");
document.story.four.focus();
return false;}

if (num5 == ""){
alert ("Please enter a , e.g ");
document.story.five.focus();
return false;}

if (num6 == ""){
alert ("Please enter an action, e.g dig, plant...");
document.story.six.focus();
return false;}

if (num7 == ""){
alert ("Please enter a second name, Alex, Paul...");
document.story.seven.focus();
return false;}

if (num8 == ""){
alert ("Please enter a second exercise, e.g cleaning, watering");
document.story.eight.focus();
return false;}

if (num9 == ""){
alert ("Please enter an emotion, e.g determined, dogged");
document.story.nine.focus();
return false;}

if (num10 == ""){
alert ("Please enter a statement, e.g comfront, challenge");
document.story.ten.focus();
return false;}

else{

//now save data
setCookie("Person",document.story.one.value, now);
setCookie("Place",document.story.two.value, now);
setCookie("Descriptive",document.story.three.value, now);
setCookie("Thing",document.story.four.value, now);
setCookie("Status",document.story.five.value, now);
setCookie("Action",document.story.six.value, now);
setCookie("Person2",document.story.seven.value, now);
setCookie("Thing2",document.story.eight.value, now);
setCookie("Emotion",document.story.nine.value, now);
setCookie("Statement",document.story.ten.value, now);

alert(document.cookie);
}

Roy Sinclair
06-11-2004, 08:54 PM
What error, errors or lack of errors are you seeing? How are you calling the validation function?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum