I am having problems with the code snippet that is used to enter the educational details of an employee in a company.
The values are added twice to a table when performed in IE. However in Firefox it works fine and gets added
only once. I am not getting any errors in the console in either case.
The fields include the degree name, name of the educational institution, year of obtaining the degree, major.
The fields degree name, institution name and major are text areas and the year is chosen from a drop down.
I am using a java script function that validates the user input to ensure that the required values are not null.
The function is
function ValidateForm(sAction,empname){
//validate all the fields before allowing the processing of the data
var bSuccessful = false;
var sErrorMessages = "";
alert(sAction);
if (document.forms[empDetails].txtDegreeName.value == 0)
{
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Degree has been entered. \n";
}else
bSuccessful = true;
if(document.forms[empDetails].txtInstName.value == "") {
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Institution Name has been entered. \n";
}
else
bSuccessful = true;
if (document.forms[empDetails].selDegreeYear.selectedIndex == 0)
{
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Year has been selected. \n";
}else
bSuccessful = true;
if(document.forms[empDetails].txtMajor.value == "") {
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Major has been entered. \n";
}
else
bSuccessful = true;
if(!bSuccessful){
alert(sErrorMessages);
return false;
}else{
if(sAction == 'ADD'){
document.forms[empDetails].action = "editEmpDetails.jsp?txtAction=ADD";
} else if (sAction == 'EDIT'){
document.forms[empDetails].action = "editEmpDetails.jsp?txtAction=EDIT";
}
document.forms[empDetails].submit();
return true;
}// end if bSuccessful
}
The above function checks if the user has to add a new entry to the table or if the user has to edit an entry that is
already available. The value for the above snippet is passed through the form below
<FORM NAME="empDetails" method="post" action="">
<INPUT TYPE="HIDDEN" NAME="txtAction" VALUE="<%=sAction%>">
<INPUT TYPE="HIDDEN" NAME="txtName" VALUE="<%=sEmpName%>">
<tr height="50">
<td align="center" valign="top"><p class="BlackA11"><INPUT name="txtDegreeName" type="text" size="10" value="<%=DegreeIN%>"></p></td>
<td align="center" valign="top"><p class="BlackA11"><INPUT name="txtInstName" type="text" size="30" value="<%=InstIN%>"></p></td>
<td><SELECT name="selDegreeYear" class="BlackA14">
<OPTION VALUE ="">Select</option>
<OPTION VALUE ="1940">1940</option>
<OPTION VALUE ="1941">1941</option>
---------------------------------
--------------------------------
<OPTION VALUE ="2007">2007</option>
<OPTION VALUE ="2008">2008</option>
</SELECT></td>
<td><p class="BlackA11"><INPUT name="txtMajor" type="text" size="15" maxlength="20" value="<%=MajorIN%>"></p></td>
<% if (sAction.equals("EDIT")){ %>
<td><p><INPUT type="submit" name="Submit" value="Update" onClick="ValidateForm('EDIT','<%=sEmpName%>')"></p></td>
<%}else{%>
<td><p><INPUT type="submit" name="Submit" value="Add" onClick="ValidateForm('ADD','<%=sEmpName%>')"></p></td>
<%}%>
<td> </td>
</tr>
</FORM>
The values are passed from the form to the javascript function that redirects to a jsp page, editEmpDetails where the
action is checked and the function is called in the bean which holds an sql query to insert the values entered in a
table or update the modified values. Can you please help me in fixing the double addition issue that i am facing.
Appreciate your help very much.
Regards
IcyChips
The values are added twice to a table when performed in IE. However in Firefox it works fine and gets added
only once. I am not getting any errors in the console in either case.
The fields include the degree name, name of the educational institution, year of obtaining the degree, major.
The fields degree name, institution name and major are text areas and the year is chosen from a drop down.
I am using a java script function that validates the user input to ensure that the required values are not null.
The function is
function ValidateForm(sAction,empname){
//validate all the fields before allowing the processing of the data
var bSuccessful = false;
var sErrorMessages = "";
alert(sAction);
if (document.forms[empDetails].txtDegreeName.value == 0)
{
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Degree has been entered. \n";
}else
bSuccessful = true;
if(document.forms[empDetails].txtInstName.value == "") {
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Institution Name has been entered. \n";
}
else
bSuccessful = true;
if (document.forms[empDetails].selDegreeYear.selectedIndex == 0)
{
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Year has been selected. \n";
}else
bSuccessful = true;
if(document.forms[empDetails].txtMajor.value == "") {
bSuccessful = false;
sErrorMessages = sErrorMessages + "No Major has been entered. \n";
}
else
bSuccessful = true;
if(!bSuccessful){
alert(sErrorMessages);
return false;
}else{
if(sAction == 'ADD'){
document.forms[empDetails].action = "editEmpDetails.jsp?txtAction=ADD";
} else if (sAction == 'EDIT'){
document.forms[empDetails].action = "editEmpDetails.jsp?txtAction=EDIT";
}
document.forms[empDetails].submit();
return true;
}// end if bSuccessful
}
The above function checks if the user has to add a new entry to the table or if the user has to edit an entry that is
already available. The value for the above snippet is passed through the form below
<FORM NAME="empDetails" method="post" action="">
<INPUT TYPE="HIDDEN" NAME="txtAction" VALUE="<%=sAction%>">
<INPUT TYPE="HIDDEN" NAME="txtName" VALUE="<%=sEmpName%>">
<tr height="50">
<td align="center" valign="top"><p class="BlackA11"><INPUT name="txtDegreeName" type="text" size="10" value="<%=DegreeIN%>"></p></td>
<td align="center" valign="top"><p class="BlackA11"><INPUT name="txtInstName" type="text" size="30" value="<%=InstIN%>"></p></td>
<td><SELECT name="selDegreeYear" class="BlackA14">
<OPTION VALUE ="">Select</option>
<OPTION VALUE ="1940">1940</option>
<OPTION VALUE ="1941">1941</option>
---------------------------------
--------------------------------
<OPTION VALUE ="2007">2007</option>
<OPTION VALUE ="2008">2008</option>
</SELECT></td>
<td><p class="BlackA11"><INPUT name="txtMajor" type="text" size="15" maxlength="20" value="<%=MajorIN%>"></p></td>
<% if (sAction.equals("EDIT")){ %>
<td><p><INPUT type="submit" name="Submit" value="Update" onClick="ValidateForm('EDIT','<%=sEmpName%>')"></p></td>
<%}else{%>
<td><p><INPUT type="submit" name="Submit" value="Add" onClick="ValidateForm('ADD','<%=sEmpName%>')"></p></td>
<%}%>
<td> </td>
</tr>
</FORM>
The values are passed from the form to the javascript function that redirects to a jsp page, editEmpDetails where the
action is checked and the function is called in the bean which holds an sql query to insert the values entered in a
table or update the modified values. Can you please help me in fixing the double addition issue that i am facing.
Appreciate your help very much.
Regards
IcyChips