www.webdeveloper.com
Results 1 to 3 of 3

Thread: JS Function Not Working

  1. #1
    Join Date
    Jun 2010
    Posts
    25

    JS Function Not Working

    I have a js function that mostly works. When the If statement isn't there, it works just great. But when I put the if statement in, I get nothing back. It's a very simple thing so I don't see where I'm going wrong.

    PHP Code:
    <?php
    $id 
    'xxx';
    ?>
    <HTML>
    <HEAD>
    <script type='text/javascript'>
    function monthly_calc(x) {
    // Get values from form
    amount = getDocumentById('amount'+x).value;
    frequency = getDocumentById('frequency'+x).value;
    when = getDocumentById('when'+x).value;

    // Compute the product.
    var product = amount * when * frequency;

    // Display product in form.
    document.getElementById('monthly'+x).value=product;
    }

    function test(id) {
        
        var test_amount= "test"+id;
        var amount = document.getElementById('test'+id).value;
        var product = amount * 100;
        If(product > 0) {
            document.getElementById(test_amount).value=product;
        }
        Else {
            document.getElementById(test_amount).value="";
            }
    }
    </script>
    <BODY

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    JavaScript is case-sensitive. So it's if and else not If and Else.

    For future debugging, I suggest the Firefox Error console (Tools -> Error Console), and the Firebug addon.

  3. #3
    Join Date
    Jun 2010
    Posts
    25
    Thanks! I'll get that add on. I didn't know js was case sensitive that way.

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