Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can you have two different validation function on one form

Status
Not open for further replies.

philrm

MIS
Jun 1, 1999
58
AU
Hi all

The error coming up is "init is not defined". Even thought it is defined within the body tag. The whole of the code is place below. The first section of code is to check that at least one field has been changed. This prevents the query from returning all the records in the table. This is working well. The second is where I need the number validation working but the the script is says "init is not defined" I wondering is it possible to have two function validation in one form. For example Onsumbit for one function which to check for the required field and for the second Onclick to validate as a number with a maximum number of characters.
****
code
**
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>


<!-- Begin
function checkFields() {
asc_order_cd = document.myForm.asc_order_cd.selectedIndex >= 1;
site_number = document.myForm.site_number.value;
surveyorone = document.myForm.surveyorone.selectedIndex >= 1;
proj_code = document.myForm.proj_code.selectedIndex >= 1;
factual_key = document.myForm.factual_key.selectedIndex >= 1;
e1 = document.myForm.e1.value;
n1 = document.myForm.n1.value;
if ((asc_order_cd == &quot;&quot;) && (site_number == &quot;&quot;) && (surveyorone == &quot;&quot;)&&(proj_code == &quot;&quot;)&&(factual_key == &quot;&quot;) && (e1 == &quot;&quot;)&&(n1 == &quot;&quot;)) {
alert(&quot;Please select or enter either a ASC, Site Number, Surveyorone, Project Code, Factual Key , Easting, Northing.&quot;);
return false;
}
else return true;
}
// End -->
</script>
<SCRIPT LANGUAGE=&quot;JavaScript&quot; src=&quot;../buttons/validation.js&quot;>
<!--

function init() {
define('e1', 'num', 'e1', 6);
define('e2', 'num', 'e2', 6);
define('n1', 'num','n1', 7);
define('n2', 'num', 'n2', 7);
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#ffffff&quot; background=&quot;../buttons/Texture_brown_051.jpg&quot; OnLoad=&quot;init()&quot;>

<font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;5&quot;><b>Locate a site </b></font><a href=&quot;#&quot; onClick=&quot;MM_openBrWindow('../html%20help/search/sitesearch.htm','test','scrollbars=yes,resizable=yes,width=360,height=350')&quot;><img src=&quot;../buttons/help01.gif&quot; width=&quot;35&quot; height=&quot;32&quot; border=&quot;0&quot;></a>
<br>
<br>
<font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Please enter / select your search
criteria below. </b></font>
<form name=&quot;myForm&quot; method=&quot;post&quot; action=&quot;testtwo.cfm&quot; onSubmit=&quot;return checkFields()&quot; >
<table width=&quot;433&quot; border=&quot;0&quot; height=&quot;179&quot;>
<tr>
<td width=&quot;142&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>ASC: </b></font></div>
</td>
<td width=&quot;281&quot;>
<select name=&quot;asc_order_cd&quot; >
<option value=&quot;allasc&quot; onFocus=&quot;document.myForm.asc_order_cd.selectedIndex >= 1;&quot; size=10 selected>(All
Asc)
<cfoutput query=&quot;order&quot;>
<option value=&quot;#code# &quot;>#code# | #description#
</cfoutput>
</select>
</td>
</tr>
<tr>
<td width=&quot;142&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Site Number:
</b></font></div>
</td>
<td width=&quot;281&quot;>
<input type=&quot;text&quot; name=&quot;site_number&quot; value=&quot;&quot; onFocus=&quot;document.myForm.site_number.value='';&quot; size=10>
</td>
</tr>
<tr>
<td width=&quot;142&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Surveyor
One: </b></font></div>
</td>
<td width=&quot;281&quot;>
<select name=&quot;surveyorone&quot; >
<option value=&quot;allsurveyor&quot; onFocus=&quot;document.myForm.surveyorone.selectedIndex >= 1;&quot; size=10 selected>(All
Surveyors)
<cfoutput query=&quot;sureone&quot;>
<option value=&quot;#surveyor_code#&quot;>#surveyor_code# | #surveyor_last_name#
</cfoutput>
</select>
</td>
</tr>
<tr>
<td width=&quot;142&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Project
Code: </b></font></div>
</td>
<td width=&quot;281&quot;>
<select name=&quot;proj_code&quot;>
<option value=&quot;allprojects&quot; onFocus=&quot;document.submitform.proj_code.selectedIndex >= 1;&quot; size=10 selected>(All
Projects)
<cfoutput query=&quot;projectcode&quot;>
<option value=&quot;#project_code# &quot;>#project_code# | #project_title#
</cfoutput>
</select>
</td>
</tr>
<tr>
<td width=&quot;142&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Factual
Key: </b></font></div>
</td>
<td width=&quot;281&quot;>
<select name=&quot;factual_key&quot; >
<option value=&quot;allfactualkey&quot; onFocus=&quot;document.myForm.factual_key.selectedIndex >= 1;&quot; size=10 selected>(All
Factual Keys)
<cfoutput query=&quot;factualkey&quot;>
<option value=&quot;#code#&quot;>#code# |#description#
</cfoutput>
</select>
</td>
</tr>
</table>
<table width=&quot;435&quot; border=&quot;0&quot; height=&quot;106&quot;>
<tr>
<td width=&quot;108&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Easting:
</b></font></div>
</td>
<td width=&quot;165&quot;>
<input type=&quot;text&quot; name=&quot;e1&quot; value=&quot;&quot; onFocus=&quot;document.myForm.e1.value='';&quot; size=10 maxlength=&quot;6&quot;>
between </td>
<td width=&quot;148&quot;>
<input type=&quot;text&quot; name=&quot;e2&quot; size=10&quot; maxlength=&quot;6&quot;>
</td>
</tr>
<tr>
<td width=&quot;108&quot;>
<div align=&quot;right&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot;><b>Northing:
</b></font></div>
</td>
<td width=&quot;165&quot;>
<input type=&quot;text&quot; name=&quot;n1&quot; value=&quot;&quot; onFocus=&quot;document.myForm.n1.value='';&quot; size=10 maxlength=&quot;7&quot;>
between</td>
<td width=&quot;148&quot;>
<input type=&quot;text&quot; name=&quot;n2&quot; size=10&quot; maxlength=&quot;7&quot;>
</td>
</tr>
</table>
<p> </p>
<p>
<input type=&quot;submit&quot; value=&quot;Find a matching site&quot; onClick=&quot;validate();return returnVal;&quot; >
</p>
</form>


 
hi philrm,
I think the problem is here:

<SCRIPT LANGUAGE=&quot;JavaScript&quot; src=&quot;../buttons/validation.js&quot;>
</script>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

//you missed ^ those ^ 2 lines

<!--
function init() {
define('e1', 'num', 'e1', 6);
. . .
 
Hi starway

What do you mean by 'philrm' missed those 2 lines. What do you have to put there when the &quot;OnLoad=&quot;init()&quot; is declare in the body tag. Also the whole of the extension is also declared as src= &quot;../buttons/validation.js&quot;. I myself cannot figure out what you want there. Could please explain what code needs to be declared at that point. Thank's

 
yogi564,
init() function is not declared in body tag, it's called there.
It is declared in <head> section of the page (as it should be done properly). Although <html><head> tags are missing in the beginning, I assume that they exist in original code.

The proper syntax of calling external .js file is this:
<SCRIPT LANGUAGE=&quot;JavaScript&quot; src=&quot;../buttons/validation.js&quot;></script>

If there's another script part it should start with another opening <script> tag.
That is what I said in my previous post.
 
Hi starway

Well half the problem is solved. But the other half of the problem is not yet solve. Can I validate the required field as well as the number field in two different format as you can see from the source code &quot;onSubmit=&quot;return checkFields()&quot; as well as &quot;onClick=&quot;validate();return returnVal;&quot; . Currently only one validation is working which is &quot;onClick=&quot;validate();return returnVal;&quot;. I need first the &quot;onSubmit=&quot;return checkFields()&quot; and then only the &quot;onClick=&quot;validate();return returnVal;&quot;. I hope this makes sense. Thank's for you previous help. I wondering if the other half can be also solve or can be solved. That's all
 
I don't see the code of validate() function.
It's called from external validation.js file and you didn't give it's code.
 
Hi starway

I can see the code of validate() function on the submit button.

Hi phil

Why don't you try changing the &quot; onClick=&quot;validate();return returnVal;&quot; to onBlur =&quot;validate();return returnVal;&quot; and put this function next to each of the input fields and then it should validate both the number as well as for the empty fields. I hope this help.

From
Yogi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top