Du kan prøve dette:
<script type="text/javascript">
function mpromile()
{
var mgenstande=document.getElementById("genstand1").value;
var mvaegt=document.getElementById("vaegt1").value;
var mtid=document.getElementById("tid1").value;
var mberegning=(12*mgenstande)/(0.7*mvaegt)-mtid;
document.getElementById("svar1").value=mberegning;
}
function kpromile()
{
var kgenstande=document.getElementById("genstand2").value;
var kvaegt=document.getElementById("vægt2").value;
var kberegning=(12*kgenstande)/( 0.6 * kvaegt);
document.getElementById("svar2").value=kberegning;
}
</script>
Eller prøv dette:
<script type="text/javascript">
function mpromile()
{
var mgenstande=document.getElementsByName("genstand1")
[0].value;
var mvaegt=document.getElementsByName("vaegt1")[0].value;
var mtid=document.getElementsByName("tid1")[0].value;
var mberegning=(12*mgenstande)/(0.7*mvaegt)-mtid;
document.getElementsByName("svar1")[0].value=mberegning;
}
function kpromile()
{
var kgenstande=document.getElementsByName("genstand2")[0].value;
var kvaegt=document.getElementsByName("vægt2")[0].value;
var kberegning=(12*kgenstande)/( 0.6 * kvaegt);
document.getElementsByName("svar2")[0].value=kberegning;
}
</script>