...

View Full Version : Trying to make a arthmitic code, with interp of the math.



marqui678
05-17-2012, 12:02 PM
I am trying to divide two numbers, display the value, then display what the value means. I am newbie, and trying to teach this to myself.

I have the division displaying in a input box with a name of "total".
I want to have the value from "total" display in an input box with a name of "interpretation".

Do I use "c" or "total" to call the value?

To write out "interpretation" do I use document.write, document.interpretation.write.?



<!doctype html>
<html><head><title>ABI</title>
<script language="javascript" type="text/javascript">
function division(){
var a=Number(document.calculator.number1.value);
var b=Number(document.calculator.number2.value);
var c=a/b;
document.calculator.total.value=c;
}


}

function interpretABI() {
if (total >= 1) {
document.write.interpretation("normal");
}
else if ((total < 1) && (c >= 0.5)) {
interpretation = "lower extremity and arterial insufficiency";
}
else (total< 0.5) {
interpretation = "severe ischemia";
}
return interpretation;
}
}

function division2(){
division()
interpretABI()

}
</script>

xelawho
05-17-2012, 01:41 PM
1. using functions just to call other function is kind of meaningless - if the code is to run sequentially, just put it all into one function
2. if you know the values from a text input are to be divided or multiplied there is no need to convert them to numbers - this will happen automatically
3. try to avoid document.write wherever possible (which is almost always) - it wipes out the rest of your page. you can use innerHTML for a div or set a text input's value just as easily
4. c is your variable, total is just the name of your text input. Simpler to work with variables.
5. you can use
else {
interpretation = "severe ischemia";
}
or

else if (c< 0.5) {
interpretation = "severe ischemia";
}
but
else (c< 0.5) {
interpretation = "severe ischemia";
}
is meaningless.

here's one way to do what you are trying to do...


<body>
<form name="calculator">
<input type="text" name="number1"/>
<input type="text" name="number2"/>
<input type="button" value="calculate" onclick="division()"/>
<input type="text" name="total"/>
</form>
<div id="results"></div>
<script language="javascript" type="text/javascript">
function division(){
var a=document.calculator.number1.value;
var b=document.calculator.number2.value;
var c=a/b;
document.calculator.total.value=c;

if (c >= 1) {
interpretation="normal";
}
else if ((c < 1) && (c >= 0.5)) {
interpretation = "lower extremity and arterial insufficiency";
}
else if (c< 0.5) {
interpretation = "severe ischemia";
}
document.getElementById("results").innerHTML=interpretation;
}

</script>
</body>

marqui678
05-17-2012, 03:47 PM
Guys thanks a that helps me a lot, and its good to see different ways of doing things.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum