Click to See Complete Forum and Search --> : help please


ThisAndThat
12-04-2003, 04:59 AM
hi

i have a problem with javascript. what i need to do is on a loan application form the applicant must give 3 years worth of employment history.

on the form it asks time with employer years and months and then the same for previous employer. (i will add a third employer when i get the code working).

i have an idae of how i want this to work.

i think that you need to add all the time with employer fields multiplying the years by 12 and then if that equals <36 you prompt them to complete the next time with employer.

the page is here (https://www.search4aloan.co.uk/unsecured/application/templates/new/app5.txt)

if anyone could help i would be extremly greatful, plus the hair is getting a bit thin.

thanks mark

TheBearMay
12-04-2003, 06:48 AM
Sounds like you're on the right track to me...

ThisAndThat
12-04-2003, 06:50 AM
i know how to add fields i just dont know how to go about multiplying by 12 first.

if anyone could give me an example it would be great.

thanks mark

clairec666
12-04-2003, 06:52 AM
var months = var years*12;

ThisAndThat
12-04-2003, 06:55 AM
heres what code i currently have

if ((theForm.m_time_in_employment_years.value *12) + (theForm.m_time_in_employment_months.value) + (theForm.m_time_in_previous_employment_years.value *12) + (theForm.m_time_in_previous_employment_months.value)) < 36
{
alert("Please enter the last 3 years of employers addresses.");
theForm.m_time_in_previous_employment_years.focus();
return (false);
}

but it completly ignores all the code.

thanks mark

Pittimann
12-04-2003, 07:36 AM
Hi!

Your code is not ignored - it produces an error:
the "<36" is outside the () of the if(blahblah) condition. Besides that your code will fail, when at least one of the four fields is left blank. To make it short - here is some code to play with. Of course the validation is not complete (I just made it: if a field is left blank or the entry in the field is not a valid numeric value, its' value is set to 0; if a field's entry is a valid numeric value, this one is calculated with)...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!--
function check(){
year1=parseInt(document.theForm.m_time_in_employment_years.value);
if (isNaN(year1)||year1=="") year1=0;
month1=parseInt(document.theForm.m_time_in_employment_months.value);
if (isNaN(month1)||month1=="") month1=0;
year2=parseInt(document.theForm.m_time_in_previous_employment_years.value);
if (isNaN(year2)||year2=="") year2=0;
month2=parseInt(document.theForm.m_time_in_previous_employment_months.value);
if (isNaN(month2)||month2=="") month2=0;
var totalMonth=year1 *12 + month1 + year2 *12 + month2;
if (totalMonth < 36)
{
alert("Please enter the last 3 years of employers addresses.");
theForm.m_time_in_previous_employment_years.focus();
return (false);
}
else alert("you've worked enough: "+totalMonth+" months");
}
//-->
</script>
</head>
<body>
<form name="theForm">
Years1: <input type="text" name="m_time_in_employment_years"><br>
Month1: <input type="text" name="m_time_in_employment_months"><br>
Years2: <input type="text" name="m_time_in_previous_employment_years"><br>
Month2: <input type="text" name="m_time_in_previous_employment_months"><br>
<input type="button" onclick="check()" value="click"><br>
</body>
</html>

Cheers - Pit

ThisAndThat
12-04-2003, 08:06 AM
thanks for the replies guys.

especially pittimann, your a star.

with a bit of editing your code worked a treat.

thanks again

Mark

Pittimann
12-04-2003, 08:12 AM
You're welcome, Mark!!!

Cheers - Pit