Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to incorporate one function into another

    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
    Code:
    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.
    Code:
    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

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    Code:
    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

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Homer,
    I'm not quite sure what you mean, as I said I'm a complete noob this code.
    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •