mrsquash Posted October 11, 2007 Share Posted October 11, 2007 Hello! I have a site that contains numerous forms. Within each form there is a common area that contains customer information (name/address/zip etc) I have written a series of javascript checks that will verify all of these fields have been filled out correctly...after I have verified these fields are correct my page should continue on to the FORM SPECIFIC field checks. My question is how should I go about including my common field checks and then have it continue with th epage specific checks? Can I do something like: function checkForm() { // ** START ** // Include the file with the common javascript checks src="../path/to/included/javascript" // Perform a request specific check if (myform.myfield.value == "") { alert( "Please enter some information." ); myform.myfield.focus(); return; } } Or is there antoher method I have to use to accomplish this? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 11, 2007 Share Posted October 11, 2007 You can't include within a function... just include the whole thing from the start. Quote Link to comment Share on other sites More sharing options...
mrsquash Posted October 11, 2007 Author Share Posted October 11, 2007 Okay, but say I have 15 checks that will be used across ALL forms. And then I have 5 unique checks for each inidivual form. I would want to reuse the 15 checks to cut down on rekeying code of course but if I included the whole thing from the start I would end up with a lot of scripts to accomplish mostly the same thing...which would defeat the purpose, right? Is it possible to include the file with the common checks, then at the end of the common checks have it call a function that checks the specific fields for the page? Something like: <script language="JavaScript"> // Run a page specific function function help() { alert("Please select the appropriate Type."); return; } // Include the generic form checks src="../my/generic/form/checks.js" // At the end of the generic form checking function call on this function function spcific() { alert("Please select the appropriate Application Type."); return; } </script> Quote Link to comment Share on other sites More sharing options...
fenway Posted October 11, 2007 Share Posted October 11, 2007 I assume you're generating this from php? If so, simply include whatever files you want... but you still can't do it inside a function. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 11, 2007 Share Posted October 11, 2007 Well, I could you could eval() some code, but that's ugly Quote Link to comment Share on other sites More sharing options...
mrsquash Posted October 11, 2007 Author Share Posted October 11, 2007 I think I must be saying something incorrect. I think we're on different levels. I have a .js file that contains a lot of common form validation checks that will be used on every page. I also have additional form validation checks that are unique to every page. I want to include the external .js file with the common functions onto each page and when a user submits the form, I want it to run through all of the common validation checks and once it is finished with those, jump straight into the unique validation checks. Common checks - contained in the external .js file Unique checks - coded into the <head></head> of each page Quote Link to comment Share on other sites More sharing options...
mainewoods Posted October 12, 2007 Share Posted October 12, 2007 <!-- Include the generic form checks --> <script src="../my/generic/form/checks.js" type="text/javascript"></script> <script language="JavaScript"> // Run a page specific function function help() { alert("Please select the appropriate Type."); return; } // any of the functions inside of checks.js can be called here, for example: var myreturn = genericcheckfunc(vara, varb); // or they can be called from the help() function above or any other function // At the end of the generic form checking function call on this function function spcific() { alert("Please select the appropriate Application Type."); return; } </script> Quote Link to comment Share on other sites More sharing options...
fenway Posted October 12, 2007 Share Posted October 12, 2007 Yeah, something like that... you just need a common "handle" for each custom script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.