• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Need Some Help !!!!

blueonline

New Member
I dont know php :confused4
i need a code that when entered a number in a text box will multiply and divide and add & substract with predefined numbers and will echo the result in another text box.

For eg
if user has entered 235644
then the script will multiply it 1256 then divide it with 23 and add 12354 and substract 12453 and show the result in another text box

i hope i have explained it :)
 
Your explanation isn't great, gimme a representation of the formula you wish to use, ie answer = ( posted x 2 ) / 3 + 15
 
Here's one way:
Code:
<form action="/test.php" method="post" name="test"><input name="number" type="text" />
<input name="" type="submit" /></form>
<?
$userinput = $_POST["number"];
$multiplier = '1256';
$divider = '23';
$add = '12354';
$subtract = '12543';
$result = ((($userinput * $multiplier)/$divider)+$add)-$subtract;
if (!$_POST)
	echo "No input number detected";
else
	echo $result;
?>
Change the various multipliers/add/subtract values as needed by changing the variables in the top. You should probably also sanitize the user input before allowing it to be posted. ;)
 
Last edited:
yea its like
the given text * 2568723232 + 134567 / 4564 - 1234 * 45677

like this..and if possible also sanitizing the text as mentioned by bear so they only post pure numbers
 
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<meta name="author" content="">
	<script language="javascript">
	// round to three decimal places, 10000 for 4 decimal places, etc
	var precision = 1000 ;
	
	function calculate( input )
	{
		if( parseInt( input ) != input )
		{
			return alert('Numnbers only please');
		}
		else
		{
			document.calc.result.value = Math.round( ( parseInt(input) * 2568723232 + 134567 / 4564 - 1234 * 45677 ) * parseInt( precision ) ) / parseInt( precision ) ;
		}
		
	}
	</script>
	<title>Untitled 2</title>
</head>

<body>
<form action="" name="calc" >
Enter a number : <input type="text" name="input" /><br />
Result : <input type="text" name="result" /><br />
<input type="button" value="Calculate" onclick="calculate( document.calc.input.value )" />
</form>
</body>
</html>

Your formula still doesn't look right .....
 
You need to be careful about the math precedence. Some operations are done first, and in a particular order. Unless bracketed, operands like multiplication and division will be done first, possibly changing your result. Operations within parentheses are done before "loose" ones.
The one I offered gives the same result as a calculator. ;)
 
I really dont need tips on how to program, I have no idea what this guy is trying to achieve, thats why I asked him for a formula, I just took the forumla he gave and put it inside a script, I have no idea what any of these numbers are for and so I have no idea what order to do the math in, that's why I said the formula still doesn't look right, because it doesnt ......
 
If you're referring to my post, it wasn't directed at you but more of a general tip. I wouldn't presume to say you needed my help. ;)
 
ok hear it wot this thing is all about... i have created a program in VB and i need to provide key online...
my program will generate randomly a 8 digit code .. which when entered here will generate another code which needs to be entered into the program in order to run
 
so you have written this in vb already??

paste the code you have written for vb, change the numbers but not the formula, you need the vb program and the website to generate the same code, so work it out in vb and I'll translate it to php, you shouldn't use javascript for this but I ddint know what you were doing, php definately ......
 
Here's the formula
(firsttextbox * 123456)/23 + 12354 - 12453 = result(in 2nd textbox) wherein the numbers 123456, 23, 12354 and 12453 are predefined
 
Last edited:
Back
Top