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!

Addition of values to a table works fine in mozilla but not in IE

Status
Not open for further replies.

icechips

Programmer
Aug 7, 2007
2
US
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>&nbsp;</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



 
Is there a variable called "empDetails" defined that is set to the string value "empDetails", or did you miss quotes from all of your code?:

Code:
document.forms[[!]'[/!]empDetails[!]'[/!]]

Do you have a URL to the page in question? Does the problem happen in IE 6, IE 7, or both?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Dan for the reply.I dont have a url to the page in question. I am using IE 7 and empDetails is the name of the form from which the values are obtained. Guess i missed the quotes there!. Is there a suggestion to help me fix the issue?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top