Results 1 to 3 of 3

Thread: Give value to a textbox when onChange value in another textbox

  1. #1
    Join Date
    Jun 2007
    Location
    Scotland, UK
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Give value to a textbox when onChange value in another textbox

    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

    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
    Code:
    <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
    Code:
    <!-- 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
    Last edited by hawkmanjacko; 06-10-2007 at 09:24 AM.

  2. #2
    Join Date
    Jun 2007
    Location
    Scotland, UK
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Update
    ----------

    Just tried

    Code:
    <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

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    calcRefund() :
    Code:
    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() :
    Code:
    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
    }
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •