View Single Post
Old 01-23-2013, 07:59 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,043
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here is one possible approach:-


Code:
<form id =  "adminForm">
Basic <Input type = "text" id = "basic" onchange = "update(1)"><br>
Net <input type = "text" id = "net" onchange = "update(2)"><br>
Gross <input type = "text" id = "gross" onchange = "update(3)"><br>
</form>

<script type = "text/javascript">
var profitmargin = .25;
var vatrate = .2;  // presumably these two values are constants

function update (x) {
var b = document.getElementById("basic");
var n = document.getElementById("net");
var g = document.getElementById("gross");

if (x==1) {
b.value = (b.value*1).toFixed(2);
n.value = (b.value * (1 + profitmargin)).toFixed(2);
g.value = (n.value * (1 + vatrate)).toFixed(2);
}

if (x==2) {
n.value = (n.value*1).toFixed(2);
b.value = (n.value / (1 + profitmargin)).toFixed(2);
g.value = (n.value * (1 + vatrate)).toFixed(2);
}

if (x==3) {
g.value = (g.value*1).toFixed(2);
n.value = (g.value / (1 + vatrate)).toFixed(2);
b.value = (n.value / (1 + profitmargin)).toFixed(2);
}

}
</script>

Note that forms should be assigned an id, not a name which is now deprecated and obsolete. Form elements should be referenced by id.

Quizmaster: "I'm just going outside, and may be some time" were the last words of which explorer?
Contestant: Columbus
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 01-23-2013 at 08:36 AM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Beginner1 (01-23-2013)