Well, I have not worked with javascript in a while, but
reading through most of the tutorials, it’s not too much
different than php. However, something is not working
correctly.
[code=php]
<script type=”text/javascript” language=”JavaScript”>
<!–
function CalculateTotals(){
f=document.calculator;
// if buysell = 1; buy. = 2; sell.
// if buy entry – stop
// if then statement here
f.first_result_temporary = Number(f.entry.value) – Number(f.stop.value);
f.first_result.value = f.first_result_temporary.toFixed(4);
…rest of code…
}
//–>
</script>
</head>
<BODY onLoad=”document.calculator.entry.focus()” >
<form NAME=”calculator” method=”post” ACTION=””>
…code.. code…
<tr><td>Buy/Sell</td>
<td><select name=”buysell” onChange=”CalculateTotals()” >
<option value=”1″ >Buy</option>
<option value=”2″ >Sell</option>
</select>
…code .. code…
<TR><TD>entry </TD>
<TD><input NAME=”entry” value=”1.0100″ size=”3″
OnBlur=”CalculateTotals()”></TD></TR>
<tr><td>stop </td>
<td><input type=”text” name=”stop” value=”50″
size=”3″ onChange=”CalculateTotals()”></td></tr>
…code … code…
<TR><TD>First Result</td><td>
<input NAME=”first_result” size=”4″ OnFocus=”document.calculator.entry.select();
document.calculator.entry.focus();”><td> entry + second_number</TD></TR>
…code…code..
The above code works just fine.
However, once I try to add an “… if then …” or a “…switch case…”
it fails.
[code=php]
if(f.buysell.value = 1){
f.first_result_temporary = Number(f.entry.value) – Number(f.stop.value);
f.first_result.value = f.first_result_temporary.toFixed(4);
}
if(f.buysell.value = 2){
f.first_result_temporary = Number(f.stop.value) – Number(f.entry.value) ;
f.first_result.value = f.first_result_temporary.toFixed(4);
}
Once I insert this code, it fails, and it also fails using “… switch case …”
I’ve also tried it using ” Number(f.buysell.value) ” also, and it still fails.
remove the statements and it works fine.