Click to See Complete Forum and Search --> : Field Validation produces null nbject error


LuigiX
10-30-2003, 03:07 PM
Hi

I have a page with two option buttons. The option button chosen will open one of two forms which are initially invisible. The forms work well until I try to make one of the fields "required". In this case the "First_Name" field on each form is validated using:
<!--webbot bot="Validation" b-value-required="TRUE" -->

Now when I try to submit either form I get the following error in the "populate_select" function:

"theform.Manager_Delegate is null or not an object"

Any help with this would be very much appreciated.

Full code below

Cheers

Luigi


<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Staff Movements</title>

<SCRIPT language="JavaScript">

function switchDiv(div_id)
{
var style_sheet = getStyleObject(div_id);
if (style_sheet)
{
hideAll();
changeObjectVisibility(div_id, "visible");
populateselect(div_id);
}
else
{
alert("sorry, this only works in browsers that do Dynamic HTML");
}
}

function getStyleObject(objectId) {
// checkW3C DOM, then MSIE 4, then NN 4.
//
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
}
else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
}
else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
} else {
return false;
}
}

function changeObjectVisibility(objectId, newVisibility) {
// first get the object's stylesheet
var styleObject = getStyleObject(objectId);

// then if we find a stylesheet, set its visibility
// as requested
//
if (styleObject) {
styleObject.visibility = newVisibility;
return true;
} else {
return false;
}
}

function hideAll()
{
changeObjectVisibility("newEmp","hidden");
changeObjectVisibility("transferEmp","hidden");
}

datasets=new Array();
datasets[0]="Manager,John Smith,Fred Bloggs,Jo Fish,Peter Johns".split(",");
datasets[1]="Delegate,Peter Johnson,Fred Allen,Eric Watson,Sue Dagg".split(",");

function populateselect(div_id){

if (div_id == "newEmp" ){
theform=document.employmentForm;
} else if (div_id == "transferEmp" ) {
theform=document.transferEmploymentForm;
}

sel1 = theform.Manager_Delegate;
sel2 = theform.Completed_By;

sel1.options.length = 0;
sel1.options.length = datasets.length;
for (i=0;i<datasets.length;i++){
sel1.options[i].text = datasets[i][0];
sel1.options[i].value = datasets[i][0];
}
sel1.selectedIndex=0;
changeselect(0);
}

function changeselect(div_id){
if (div_id == "newEmp" ) {
theform=document.employmentForm;
} else if (div_id == "transferEmp" ) {
theform=document.transferEmploymentForm;
}

sel1 = theform.Manager_Delegate
sel2 = theform.Completed_By

dataset=sel1.selectedIndex;
sel2.options.length = 0;
sel2.options.length = datasets[dataset].length-1;
for (i=1;i<((datasets[dataset].length));i++){
sel2.options[i-1].text = datasets[dataset][i];
sel2.options[i-1].value = datasets[dataset][i];
}
sel2.selectedIndex=0;
}

</script>

</head>

<body>
<p><b><font size="6">Employee Movements</font></b> </p>
<hr>
<table id="AutoNumber1" style="BORDER-COLLAPSE: collapse" borderColor="#111111" height="99" cellSpacing="0" cellPadding="0" width="400" border="0">
<tr>
<td height="33"><b>Select Category:</b></td>
</tr>
<tr>
<td height="21">
<input onclick="switchDiv('newEmp');" type="radio" CHECKED value="newEmp" name="form_type">New Employee</td>
</tr>
<tr>
<td height="21">
<input onclick="switchDiv('transferEmp');" type="radio" value="transferEmp" name="form_type">Transferring</td>
</tr>
</table>

<div id="transferEmp" style="position: absolute; top: 285; left: 3; visibility: hidden; width: 900; height: 903">
<form name=transferEmploymentForm method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" s-email-format="TEXT/PRE" s-email-address="lloydc@northpower.com" b-email-label-fields="TRUE" b-email-subject-from-field="FALSE" s-email-subject="Staff Movement Form - Transfer" s-builtin-fields startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" -->
<table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" id="AutoNumber2" bgcolor="#FFFFFF">
<tr>
<td align="right" width="150">Authorising Manager:</td>
<td width="350">
<select size="1" name="Authorising_Manager" tabindex="1">
<option>John Smith</option>
<option>Fred Bloggs</option>
<option>Jo Fish</option>
<option>Peter Johns</option>
</select></td>
</tr>
<tr>
<td align="right" width="150">Completed By:</td>
<td width="350">
<select name="Manager_Delegate" onchange="changeselect()" tabindex="2">
</select></td>
</tr>
<tr>
<td align="right" width="150">Name:</td>
<td width="350">
</select>
<select name="Completed_By" tabindex="3">
</select><br>
</td>
</tr>
</table>
<br>
<table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" id="AutoNumber3" bgcolor="#FFFFFF">
<tr>
<td width="126" align="right">First Name:</td>
<td width="1">
<!--webbot bot="Validation" b-value-required="TRUE" --><input type="text" name="First_Name" size="22" tabindex="4"></td>
</tr>
<tr>
<td width="126" align="right">Last Name:</td>
<td width="1">
<input type="text" name="Last_Name" size="22" tabindex="5"></td>
</tr>
<tr>
<td width="146" align="right">From Department:</td>
<td width="39"><select size="1" name="Department" tabindex="10">
<option>Administration</option>
<option>Finance</option>
<option>HR Compliance</option>
</select></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="Form_Sent"><input type="reset" value="Reset" name="B2"></p>
</form>
</div>

<div id="newEmp" style="position: absolute; top: 285; left: 3; visibility: hidden; width: 900; height: 903">
<form name=employmentForm method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" s-email-format="TEXT/PRE" s-email-address="lloydc@northpower.com" b-email-label-fields="TRUE" b-email-subject-from-field="FALSE" s-email-subject="Staff Movement Form - New" s-builtin-fields startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="1"><!--webbot bot="SaveResults" endspan i-checksum="43406" -->
<table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" id="AutoNumber2" bgcolor="#FFFFFF">
<tr>
<td align="right" width="150">Authorising Manager: </td>
<td width="350">
<select size="1" name="Authorising_Manager" tabindex="1">
<option>John Smith</option>
<option>Fred Bloggs</option>
<option>Jo Fish</option>
<option>Peter Johns</option>
</select></td>
</tr>
<tr>
<td align="right" width="150">Completed By:</td>
<td width="350">
<select name="Manager_Delegate" onchange="changeselect()" tabindex="2">
</select></td>
</tr>
<tr>
<td align="right" width="150">Name:</td>
<td width="350">
</select>
<select name="Completed_By" tabindex="3">
</select><br>
</td>
</tr>
</table>
<br>
<table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" id="AutoNumber3" bgcolor="#FFFFFF">
<tr>
<td width="96" align="right">First Name:</td>
<td width="1">
<!--webbot bot="Validation" b-value-required="TRUE" --><input type="text" name="First_Name" size="22" tabindex="4"></td>
</tr>
<tr>
<td width="96" align="right">Last Name:</td>
<td width="1">
<input type="text" name="Last_Name" size="22" tabindex="5"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="Form_Sent"><input type="reset" value="Reset" name="B2"></p>
</form>
</div>

</body></html>

Khalid Ali
10-30-2003, 08:49 PM
make sure that elements that are being pointed by the error are present in the page,make sure about the spellings JS is case sensitive.