Jump to content
php.lv forumi
  • 0

sum pa daudziem textbox-iem


tomaac

Question

Man ir skaitā 20 texta lauki, kuros iekšā var rakstīt skaitļus.

Tad man ir lauks, kurā jau ir visu šo skaitļu summa.

 

Nepieciešams, lai mainot kādu no texta laukiem, automātiski izmaiņas šī summa (nav svarīgi vai tas notiek pēc tam kad zaudēts focus vai rakstīšanas laikā).

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Paraugam:

<html>
<head>
	<title>Sum</title>
	<script type="text/javascript">

		function sum()
		{
			var nr1 = document.getElementById('nr1').value;
			var nr2 = document.getElementById('nr2').value;
			var nr3 = document.getElementById('nr3').value;
			var sum = (nr1 * 1) + (nr2 * 1) + (nr3 *1);
			document.getElementById("sum").innerHTML = sum;
		}

	</script>
</head>
<body onload="sum();">
	<table>
		<tr><td>1: <input type="text" id="nr1" name="nr1" value="1" OnChange="sum();" /></td></tr>
		<tr><td>2: <input type="text" id="nr2" name="nr2" value="2" OnChange="sum();" /></td></tr>
		<tr><td>3: <input type="text" id="nr3" name="nr3" value="3" OnChange="sum();" /></td></tr>
		<tr><td>Summa: <b id="sum"></b></td></tr>
	</table>
</body>
</html>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...