SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Syntax problem?

  1. #1
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Kent in Uk
    Posts
    538
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Syntax problem?

    Hi

    I have written some javascript that works without the if- else statement. So I know its something to do with that statement. What I want the script to do is if user puts a umber above 6 intextfieldA (or num1), textfield3 (or num3) will equal 7

    do I seem to be on the right track. Script is below:

    <head>
    <script type = "text/javascript">


    function charge()
    {
    num1 = window.document.form1.textfieldA.value;
    num2 = window.document.form1.textfield4.value;
    num3 = window.document.form1.textfield2.value;
    total = (num1 * num2 ) + (num3*1);
    window.document.form1.textfield3.value = total;


    if (num1 > 6)
    {
    total = (num1 * num2) + 7;
    }
    End if
    }
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form name="form1">
    <table width="732" border="1">
    <tr>
    <td width="65">Name</td>
    <td width="144">Quantity</td>
    <td width="144">Price</td>
    <td width="146">Delivery Charge </td>
    <td width="49"> confirm </td>
    <td width="384">Total</td>
    </tr>
    <tr>
    <td>White Lilly </td>
    <td><label>
    <input type="text" name="textfieldA" value = ""/>
    </label></td>
    <td><label>
    <input name="textfield4" type="text" value="20.00" />
    </label></td>
    <td><input type="text" name="textfield2" value = "2.50" /></td>
    <td><label>
    <input type="button" name="button" onClick ="javascript:charge()" value="OK" />
    </label></td>
    <td><label>
    <input type="text" name="textfield3" Value = ""/>
    </label></td>
    </tr>

    thanks for your help

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Morning
    Code:
    function charge()
    {
    num1 = window.document.form1.textfieldA.value;
    num2 = window.document.form1.textfield4.value;
    num3 = window.document.form1.textfield2.value;
    
    if (num1 > 6)
    {
    total = (num1 * num2) + 7;
    }
    else {
    total = (num1 * num2 ) + (num3*1);	
    }
    window.document.form1.textfield3.value = total;
    }
    should do it
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •