View Full Version : Adding 3 Values From Prompt

12-15-2006, 01:20 AM
Can anyone help me out with the code (or pointing me to a similar code)?

I am creating childrens numeracy website and I need a script that upon a button click loads a prompt window. The user can enter 3 integers (into 3 different prompts) and the added value of the 3 integers is printed to the screen.

Didn't really know any JavaScript untill about 5 minutes ago so please be kind!



12-15-2006, 02:41 AM
Here a webpage that does what I think you want:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">


<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />

<script type="text/javascript">
/* <![CDATA[ */
function add3numbers()
var firstNum = parseFloat(prompt('Please enter the first number', ''));
var secondNum = parseFloat(prompt('Please enter the second number', ''));
var thirdNum = parseFloat(prompt('Please enter the third number', ''));

var result = firstNum + secondNum + thirdNum;

var resultString = document.createTextNode('The result is: ' + result);
var resultSpan = document.createElement('span');

/* ]]> */

<button onclick="add3numbers()">Click here to add 3 numbers</button>

It works with floating-point numbers also.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum