Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-05-2012, 02:10 AM   PM User | #1
mahapatra
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mahapatra is an unknown quantity at this point
JS Script implementation problem

Hello all
am new to to java scripting and trying to learn
can anyone help me in this block of code.
This is my javascript code.
Code:
// JavaScript Document for EmployeeDB
//Validating On Focus
function foc(x)
{
	if(x==1)
		if(document.FrmEmp.ECode.value=="Enter Code Here")
			document.FrmEmp.ECode.value="";
	if(x==2)
		if(document.FrmEmp.EName.value=="Enter Name Here")
			document.FrmEmp.EName.value="";
	if(x==3)
		if(document.FrmEmp.ESal.value=="Enter Salary Here")
			document.FrmEmp.ESal.value="";
	if(x==4)
		if(document.FrmEmp.EPost.value=="Enter Post Here")
			document.FrmEmp.EPost.value="";		
}
//Validating On Blur
function los(x)
{
	if(x==1)
		if(document.FrmEmp.ECode.value=="")
			document.FrmEmp.ECode.value="Enter Code Here";
	if(x==2)
		if(document.FrmEmp.EName.value=="")
			document.FrmEmp.EName.value="Enter Name Here";
	if(x==3)
		if(document.FrmEmp.ESal.value=="")
			document.FrmEmp.ESal.value="Enter Salary Here";
	if(x==4)
		if(document.FrmEmp.EPost.value=="")
			document.FrmEmp.EPost.value="Enter Post Here";		
}
//Calculating corresponding values
function calc()
{
	var sal,hra,da,ta,pf,gross,it,net;
	sal=document.FrmEmp.ESal.value;
	alert("Hell");
	if(sal<=5000)
	{
		hra=sal*7.5/100;
		da=sal*11.22/100;
		ta=sal*3.16/100;
		pf=sal*1.93/100;
		gross=sal+hra+da+ta;
		it=0;
		net=gross-(pf+it);
	}
	if(sal>5000 and <=15000)
	{
		hra=sal*11.26/100;
		da=sal*20.26/100;
		ta=sal*7.97/100;
		pf=sal*4.26/100;
		gross=sal+hra+da+ta;
		it=gross*1.93/100;
		net=gross-(pf+it);
	}
	if(sal>15000 and <=40000)
	{
		hra=sal*18.26/100;
		da=sal*28.72/100;
		ta=sal*11.65/100;
		pf=sal*7.22/100;
		gross=sal+hra+da+ta;
		it=gross*3.16/100;
		net=gross-(pf+it);
	}
	if(sal>45000)
	{
		hra=sal*25.25/100;
		da=sal*40.45/100;
		ta=sal*16.16/100;
		pf=sal*9.75/100;
		gross=sal+hra+da+ta;
		it=gross*5.55/100;
		net=gross-(pf+it);
	}
}
And this is the associated HTML
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Employee Database</title>
<script type="text/javascript" src="EmployeeDBValidation.js"></script>
</head>
<body>
<table width="700" align="center" border="1">
<tr>
<td>
<form name="FrmEmp" action="" method="post">
<table width="700" height="427" border="0"  bgcolor="#FFFFCC">
<tr bgcolor="#66FF99">
<th align="center" colspan="4">Employee Database</th>
</tr>
<tr bgcolor="#66FF99">
<td colspan="4"><hr  size="3" color="#000000"/></td>
</tr>
<tr>
<td width="306" rowspan="14"><img  src="images/Employee Profile Management System.jpg" width="300" height="400"</td>
<td width="171"><strong>Employee Code</strong></td>
<td colspan="2"><input type="text" name="ECode" value="Enter Code Here"  onfocus="foc(1)" onblur="los(1)" maxlength="10" size="11"/></td>
</tr>
<tr>
<td width="171"><strong>Employee Name</strong></td>
<td colspan="2"><input type="text" name="EName" value="Enter Name Here" onfocus="foc(2)"  onblur="los(2)" maxlength="45" size="20"/></td>
</tr>
<tr>
<td width="171"><strong>Employee Gender</strong></td>
<td colspan="2"><input  type="radio" name="EGen"  value="M" checked="checked"/>Male<input type="radio" name="EGen" value="F" />Female</td>
</tr>
<tr>
<td width="171"><strong>Employee City</strong></td>
<td colspan="2"><select name="ECity">
<option selected="selected">--Select--</option>
<option>Bhubaneswar</option>
<option>Cuttack</option>
<option>Puri</option>
<option>Rourkela</option>
<option>Berhampur</option>
<option>Sambalpur</option>
<option>Baripada</option>
<option>Cuttack</option>
<option>Balasore</option>
</select></td>
</tr>
<tr>
<td width="171"><strong>Employee Salary</strong></td>
<td colspan="2"><input type="text" name="ESal"  value="Enter Salary Here"  onfocus="foc(3)" onblur="los(3)" maxlength="20" size="12"/></td>
</tr>
<tr>
<td width="171"><strong>Employee Post</strong></td>
<td colspan="2"><input type="text" name="EPost"  value="Enter Post Here"  onfocus="foc(4)"  onblur="los(4)" size="11" maxlength="20"/></td>
</tr>
<tr>
<td width="171"><strong>HRA</strong></td>
<td colspan="2"><input type="text" name="HRA"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><strong>DA</strong></td>
<td colspan="2"><input type="text" name="DA"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><strong>TA</strong></td>
<td colspan="2"><input type="text" name="TA"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><strong>PF</strong></td>
<td colspan="2"><input type="text" name="HRA"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><strong>Gross</strong></td>
<td colspan="2"><input type="text" name="Gross"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><strong>IT</strong></td>
<td colspan="2"><input type="text" name="IT"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><strong>Net Income</strong></td>
<td colspan="2"><input type="text" name="Net"  readonly="readonly" maxlength="5" size="5"/></td>
</tr>
<tr>
<td width="171"><input type="submit" value="Calculate and Submit to DB" /></td>
<td width="68"><input type="button" value="Calculate" onclick="calc()" /></td>
<td width="137"><input type="reset" value="Reset and Re-Enter" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
I am facing a problem in the calc(). When i comment out that function the foc() and los() work. but when I uncomment it, they stop working.

tried using jlint too, but it was far beyond my comprehension :P

some one please tell me the error
mahapatra is offline   Reply With Quote
Old 10-05-2012, 02:25 AM   PM User | #2
mahapatra
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mahapatra is an unknown quantity at this point
Sorry, found the error

Sorry all
i found the error
was using and instead of &&
mahapatra is offline   Reply With Quote
Old 10-05-2012, 02:25 AM   PM User | #3
mahapatra
New to the CF scene

 
Join Date: Oct 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mahapatra is an unknown quantity at this point
Admin please mark as solved.
mahapatra is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:41 AM.


Advertisement
Log in to turn off these ads.