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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Integration of two external .js scripts

    I am using two external .js files for my email forms.

    The first (see below) is the one that checks blank fields.

    The second (see below) is the one that checks whether the box is ticked.

    The problem is: Depending on which one I need to use in a form, I "name" the form as: "form1" or "form2". I do this by adding a name attribute to the <form> tag. However, there are some cases that I need to use both of these functions.

    How can I do this?

    Do I need to integrate these two or is it possible to put both separately to work?

    Thanks!


    ----

    FIRST

    Code:
    function validate()
    
    { 
      for(i=0;i<document.form1.elements.length;i++)
      { 
     	  if(document.form1.elements[i].value=="")
    		{
    		  alert('Please fill all the fields!');
    		  return false;
    		}
    	}
    	document.form1.submit();
    }



    SECOND

    Code:
    function validate()
    { 
    	for(i=0;i<document.form2.elements.length;i++)
    	{
    		if(document.form2.elements[i].type.toLowerCase()=='checkbox')
    		{  
    			if(document.form2.elements[i].checked==false)
    			{
    				if(document.form2.elements[i].faultDescription=="")
    				{                             
    					alert('Fill Out all fields');
    					return false;
    				}
    				else
    				{
    					alert(document.form2.elements[i].faultDescription); 
    					return false;
    				}
    			}
    		}
    		else
    		{
    			if(document.form2.elements[i].value=="")
    			{
    				if(document.form2.elements[i].faultDescription=="")
    				{                             
    					alert('Fill Out all fields');
    					return false;
    				}
    				else
    				{
    					alert(document.form2.elements[i].faultDescription); 
    					return false;
    				}		
    			}
    		}
    	}
    	document.form2.submit();
    }

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    simply put the both for(){} circles within the same validate function.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    please show me how.

    thanks.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    wait a minte... u confused me... You have one form or two? Have u handle the form with onsubmit event, or the submit button with onclick? Which is your final purpose anyway?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your requests I would have to agree makes absolutely no sense what so ever, your 2nd validate validates the same as your 1st validate plus an ekstra checkBox validation.

    Why you code your validate to a specific form name is beyond me though.
    Last edited by Garadon; 01-07-2005 at 05:36 PM.


  •  

    Posting Permissions

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