[Javascript] newbie question

wallylaw at yahoo.com wallylaw at yahoo.com
Wed Nov 6 22:36:17 CST 2002


Cheryl,
You've probably already gotten some solutions (I can't check my e-mail
via my regular account), but in case you haven't heard back on this,
this should work for you:
< script language="JavaScript" > < !--
function add() {
	A = openp2.ALA1FT.value;
	B = openp2.MLS1FT.value;
	openp2.total.value = (A + B);
	verify();
}

function verify() {
	if (openp2.total.value != openp2.STAFF1FT.value) {
		alert ("Check your addition.");
	}
}
/ /-- > < /script>

The last line in your form code should omit the call to "verify()",
since that is taken care of by the call to "add()":
< input type=button name= b1 value="Submit data" onClick = add(); >

HTH,
Tommy Simmons
Employment Law Advisory Network
www.employmentlawadvisors.com

--- Cheryl Kirkpatrick <cheryl at leo.scsl.state.sc.us> wrote:
> I am trying to use Javascript to verify the addition in an online
> form.
> My boss wants the user to supply the sum of several numbers and than
> have the form verify the sum. I am trying to get a simple version
> working before I plug it in my form. The addition works fine but I
> can't
> get the If then statement to work.
> 
> Can you tell me what I am doing wrong?
> 
> 
> function add() {
> A = document.openp2.ALA1FT.value
> B = document.openp2.MLS1FT.value
> A = Number(A)
> B = Number(B)
> C = (A + B)
> document.openp2.total.value = C
> 
> }
> function verify() {
> If (document.openp2.total.value != 'STAFF1FT');
> alert ("Check your addition");
> }
> 
> </SCRIPT>
> 
> </head>
> 
> <body>
> 
> <FORM name="openp2">
> l<input type="hidden" name="total" size="3" maxlength="3">
> 
> <p>full time librarians: <input type="text" name="ALA1FT" size="3"
> maxlength="3" value=""></p>
> 
> <p>part time librarians: <input type="text" name="MLS1FT" size="3"
> maxlength="3" value=""></p>
> 
> 
> Total staff: <input type="text" name="STAFF1FT" size="3"
> maxlength="3">
> 
> 
> <p>
> 
> <input type=button name= b1 value="Submit data" onClick = add();
> verify()>
> 
> </p>
> 
> 
> </form>
> 
> Thank you in advance!
> --
> Cheryl Kirkpatrick
> Web Administrator/
> Information Technology Librarian
> South Carolina State Library
> http://www.state.sc.us/scsl/
> Telephone: 803.734.5831

__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2



More information about the Javascript mailing list