www.webdeveloper.com
Results 1 to 7 of 7

Thread: Need Some Help With a Function PLZ..

  1. #1
    Join Date
    Jul 2003
    Posts
    18

    Question Need Some Help With a Function PLZ..

    Write a function that will calculate and return the amount that should be paid as a tip for a restrurant bill.

    Assume 20%

    Use input box 4 user input. Im lost already.

    Thanks in advanced!!

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    get value from the text field

    var val = (parseInt(document.formName.textfieldName.value)
    //(presuming that values is always a number

    //now calculate the tip
    val = (val*.20).toFixed(2);
    //if you want the tip added to the toal then

    //val = (val+(val*.20)).toFixed(2);

    //now re populate the text field
    document.formName.textfieldName.value = val

    //or see an alert box

    alert("Tip to be paid = "+val)
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Jul 2003
    Posts
    18
    coo thanks, I'll reply back if I get stuck. I think I shouldn't be though.

  4. #4
    Join Date
    Jul 2003
    Posts
    18
    Still needing some help.....I think my whole thing is wrong.?
    Attached Files Attached Files

  5. #5
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    Here you fo

    <head>
    <script type="text/javascript">
    <!--
    function Process(val){
    var val = (isNaN(parseInt(val)))? 00arseInt(val);
    if(val==00){document.form1.t1.value="0"; return false;}
    val = (val+(val*.20)).toFixed(2);
    document.form1.total.value = val;
    }

    //-->
    </script>
    </head>
    <body>
    <form name="form1" action="" onsubmit="" method="post" enctype="text/plain">
    Enter Amount <input type="text" name="t1" maxlength="4" onkeyup="Process(this.value);" size="4"/> * 20% = <input type="text" name="total" maxlength="4" size="4"/>
    </form>
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  6. #6
    Join Date
    Jul 2003
    Posts
    18
    thanks

  7. #7
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120


    You are welcome
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles