PDA

View Full Version : Give value to a textbox when onChange value in another textbox



hawkmanjacko
06-10-2007, 08:02 AM
Hi guys. I am writing quite a basic form to which shall calculate a refund in accordance with a refund matrix.

The "user" enters the Daily Cost and then the Day's Offline and hits the calculate button. The total amount due to be refunded is then placed within a readonly textbox.

I have done all the above so well so good :rolleyes:

I am finding it extremely difficult to do the next step that I would like some help on. I would like a message, in accordance with the total refund if greater than 0 then message = "example of a message" and if greater than 20 then message = "another example of a message" --> this message should appear in another textbox.

FORM

<div align="right">
<form name="refund">
Daily Cost: <input type="text" id="dailycost" name="dailycost" size="10" value="0.">&nbsp;&nbsp;
Day's Offline: <input type="text" id="downtime" name="downtime" size="10" onkeypress="return isNumberKey(event)" maxlength="3">&nbsp;&nbsp;
<input type="button" id="calc" name="calc" value="Calculate" onClick="calcRefund()">&nbsp;&nbsp;
Refund Due: <b>&#163;</b><input type="text" id="adjustment" name="adjustment" size="10" style="font-weight:bold;" readonly><br />
<input type="text" id="info" name="info" size="60" readonly><input type="reset" id="reset" name="reset" value="Reset">
</form></div><p />

SCRIPT SO FAR

<!-- Begin
function calcRefund() {
var dailycost = eval(document.refund.elements[0].value)
var downtime = eval(document.refund.elements[1].value)
var adjustmentrefund = dailycost * downtime
document.refund.adjustment.value=adjustmentrefund;
}
// End -->

function isNumberKey(evt) {

var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}

Any help with this would be fantastic! Thanks

hawkmanjacko
06-10-2007, 08:16 AM
Update
----------

Just tried


<script type="text/javascript">
<!--
function test(){

Info=document.forms["refund"]["adjustment"].value

if (Info >=20){
myOutput.value='Escalate adjustment amount to F&A'
}
else{
myOutput.value='Adjustment amount within range of agent allowance'
}

document.forms["refund"]["info"].value= myOutput
}

//-->

</script>.........without success :(

tech_support
06-10-2007, 08:45 AM
calcRefund() :


function calcRefund() {
var f = document.forms['refund']
var dailycost = parseInt(f.elements[0].value)
var downtime = parseInt(f.elements[1].value)
var adjustmentrefund = dailycost * downtime
f.elements['adjustment'].value=adjustmentrefund;
}


test() :


function test(){

Info=document.forms["refund"].elements["adjustment"].value

if (Info > 19){
myOutput.value='Escalate adjustment amount to F&A'
}
else{
myOutput.value='Adjustment amount within range of agent allowance'
}

document.forms["refund"].elements["info"].value= myOutput
}