Jump to content

Include within a function?


mrsquash

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/72826-include-within-a-function/
Share on other sites

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>

 

 

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

<!--  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>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.