PDA

View Full Version : I Need Help Regarding Creating a JavaScript



KIKAN
Apr 9th, 2007, 02:30 PM
Hi Friends i am new to this forum accualy i want to create A Java Script to be implemented on http://hydbullion.org
its a calculating script

like this

This Value Editable 675.20
+ 1.30
This Value Editable * 43.10
This Vale Fixed * 31.99
This Vale Fixed + 10300
This Vale Fixed * 101
This Vale Fixed / 100


And The Final Answer =675.20+1.30*43.10*31.99+10300*101/100=952467

I Will Be Great Full If Some One Can create This Script For Me


Regards
Kikan

Zorro_
Apr 9th, 2007, 04:20 PM
I am new too but may be some one can give you a better one..:thumbsup:
<html>
<head>
<title>Caluclate</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function calc() {
var a =31.99;
var b =10300;
var c = 101;
var d = 100;
var e = prompt("Enter your the no: 675.20", "675.20")
var f = prompt("Enter your the no: 43.10", "43.10")
var result=eval((e+1.30*f*a+b*c)/d);
alert("Result: " + result);
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<input type="submit" name="Submit" value="click me" onclick="calc();">
</body>
</html>

Philip M
Apr 9th, 2007, 04:50 PM
Hm, I have the idea that this is an assignment and zorro knows the "model answer". But as I understand it the result should be an integer. Zorro's script returns NaN due to the entered values being strings.

Try this:-

<FORM action="javascript:void(0)" onsubmit="calcPrice(this)">
<p> Value 1
<input type="text" id="value1" name = "value1" value = 675.20></p>
<br >
<p> Value 2
<input type="text" id="value1" name = "value2" value = 43.10>
<br>
</FORM>

<SCRIPT type = "text/JavaScript">
var value1 = parseFloat(document.getElementById("value1").value);
var value2 = parseFloat(document.getElementById("value2").value);
var value3 = 31.99;
var value4 = 10300;
var value5 = 101;
var value6 = 100;
function calcResult() {
result = ((value1 + 1.3) * value2 * value3 + value4) *value5 / value6;
result = parseInt(result);
alert ("The result is: " + result);
}
</SCRIPT>

<input type = "button" value = Calculate onclick="calcResult()">

</BODY>
</HTML>

KIKAN
Apr 10th, 2007, 06:53 AM
Friends Both are not working:confused:

Philip M
Apr 10th, 2007, 07:34 AM
See corrected version above (typo corrected)

KIKAN
Apr 10th, 2007, 08:21 AM
THE RESULT IS "NaN"

This Also Not Working

I Made One One But When I Add +1.30 THe Same Problem Accurs With Me


<html>
<script javascript>
<!-- Begin
//
// Server Side Code Would Be Required Above Script To Set Text Field Values From Database on OnLoad()
//

function DoMath(){
var Gold = document.frmData.Gold.value
var Exchange = document.frmData.Exchange.value
var a = 1.30
var b = 31.99
var c = 10300
var Costing = ( Gold * Exchange * b + c ) * 101 / 100
document.frmData.Costing.value = Costing
}
<!-- End
</script>
<body onload="DoMath()">
<form name="frmData" method="POST" >
Gold:<br>
<input type="text" onchange="DoMath()" name="Gold" size="20"></p>
<p>Exchange:<br>
<input type="text" onchange="DoMath()" name="Exchange" size="20"></p>
<p>Costing:<br>
<input type="Numeric" name="Costing" size="20" font="arial"><br>
</p>
</form>
</body>
</html>

Philip M
Apr 10th, 2007, 04:18 PM
See corrected version above (typo corrected)

I have made a further modification to remove a duplicate line (Sorry!).
It now works fine for me!

KIKAN
Apr 11th, 2007, 07:02 AM
Sorry Boss I Get "this Result Is "NaN""

david_kw
Apr 11th, 2007, 07:24 AM
Philip's code was working in IE but gave NaN in FF. There was a typo where the second text input had an id="value1" instead of id="value2". It should be fixed in the below code (obviously it is missing the <html> tag and such but will still work).



<FORM action="javascript:void(0)" onsubmit="calcPrice(this)">
<p> Value 1
<input type="text" id="value1" name = "value1" value = 675.20></p>
<br >
<p> Value 2
<input type="text" id="value2" name = "value2" value = 43.10>
<br>
</FORM>

<SCRIPT type = "text/JavaScript">
var value1 = parseFloat(document.getElementById("value1").value);
var value2 = parseFloat(document.getElementById("value2").value);
var value3 = 31.99;
var value4 = 10300;
var value5 = 101;
var value6 = 100;
function calcResult() {
result = ((value1 + 1.3) * value2 * value3 + value4) *value5 / value6;
result = parseInt(result);
alert ("The result is: " + result);
}
</SCRIPT>

<input type = "button" value = Calculate onclick="calcResult()">

</BODY>
</HTML>


david_kw

KIKAN
Apr 12th, 2007, 06:33 AM
Thx This Works