Stupid Javascript question

Jim Skehill JimS-pFJmkVL1u50 at public.gmane.org
Mon Feb 14 14:22:22 UTC 2005


Our you sure you have that right? 

I note that you change the variable name from a to A, but, in javascript,
variable names are case-sensitive so this will generate an error. 

I typed up the following html document as a test.
<html>
<head>
	<title>Add Test</title>
	<script language="javascript" type="text/javascript">
		function AddTest(input) {
			a = 2;
			input.value = a+a;
		}
	</script>
</head>

<body>
	<table >
	<tr >
	<td class="wizLabel" >
		Add Test
	</td >
	<td >
		<input name="JAVASCRIPT_TEST"  value="42"  class="wizInput"
onchange="AddTest(this)" >
	</td >
	</tr >
	<tr >
	<td class="wizLabel" >
		Move Here
	</td >
	<td >
		<input name="MOVE_HERE"  value="42"  class="wizInput">
	</td >
	</tr >
	</table >
</body>
</html>

Place the cursor on the edit labelled Add Test , type in anything, then move
away (e.g. to the edit labelled Move Here). The contents of the first edit
gets replaced with the result calculated by the javascript function AddTest.
On both IE and Firefox the result is 4.

BTW if you replace the line: 
	a = 2: 
with
	a = '2': 
then you get 22.

Regards,
Jim.

-----Original Message-----
From: Lance F. Squire [mailto:lance-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org]
Sent: Friday, February 11, 2005 4:25 PM
To: tlug-lxSQFCZeNF4 at public.gmane.org
Subject: [TLUG]: Stupid Javascript question


How do I add two values?

a=2;

A*A=4 but A+A=22

Been searching google to no avail...

Thanks in advance.
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list