...

View Full Version : How to incorporate one function into another



floodster
11-01-2006, 03:38 PM
Hi,
I'm a complete noob to Javascript but I've managed to implement some pretty basic form validation to check if a form item is blank.
What I want to incorporate is another check to see if a form item has 2 or more words.
Here is my 'blank validation' script


function notblank(value) {
return (value != "")?true:false;
}
function validate_form2(fadd)
{
with (fadd)
{
if (!notblank(ftitle.value)) {
alert("Title is mandatory");
ftitle.focus();
return false
}
if (!notblank(fpath.value)) {
alert("Filepath is mandatory");
fpath.focus();
return false
}
if (!notblank(fdescription.value)) {
alert("Description is mandatory");
fdescription.focus();
return false
}

}
}

What I want to add in is the below code but I'm not sure where or how to do it. They both work fine independently but I only want the user to 'submit' the form once.


function checkwords(cur){
//change min # of words to determine below
var minwords=2
if (document.images){
var temp=cur.fdata.value.split(" ")
if (temp.length<minwords){
alert("You must enter at least 2 keywords!")
return false
}
}
}


Thanks in advance

homerUK
11-01-2006, 03:44 PM
function notblank(value) {
return (value != "")?true:false;
}
function validate_form2(fadd)
{
with (fadd)
{
if (!notblank(ftitle.value)) {
alert("Title is mandatory");
ftitle.focus();
return false
}
if (!notblank(fpath.value)) {
alert("Filepath is mandatory");
fpath.focus();
return false
}
if (!notblank(fdescription.value)) {
alert("Description is mandatory");
fdescription.focus();
return false
}
if (checkwords(cur)) {
return true;
} else {
return false;
}

}
}


you could use it like that - you'd need to pass what ever "cur" is to the validate_form2() function... something like

validate_form2(fadd,cur)

hope that helps :)

floodster
11-01-2006, 04:29 PM
Homer,
I'm not quite sure what you mean, as I said I'm a complete noob this code.
Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum