Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: java script help  (Read 2300 times)

0 Members and 1 Guest are viewing this topic.

garyg

    Topic Starter


    Newbie

    java script help
    « on: May 02, 2009, 09:03:22 PM »
    here is a script I am writing and having problems with.  It keeps coming up with an object error.  What have I done wrong.   Thanks in advanced.



    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>ball calculator</title>
    <script type="text/Javascript">
    function calcball(ball, qty){
         var price = 0.00;
         msg = "";
         if (ball == "The Cell") price = 150.00;
         else if (ball == "Cell Pearl") price = 200.00;
         else if (ball == "Cell Rouge") price = 220.00;
         else if (ball == "Agent") price = 160.00;

         price *= qty;
         msg += "Total price is:  $" + price;
         alert(msg);|
    }
    </script>
    </head>

    <body>

    <h1> Ball Order Form</h1>
    <form name="ballorder">
    <tableborder="0" cellpadding="4" cellspacing="3">
       <tr>
         <td><label>Select Ball:</label></td>
         <td><select name="ball" size="1">
             <option value="The Cell">The Cell</option>
             <option value="Cell Pearl">Cell Pearl</option>
             <option value="Cell Rogue">Cell Rogue</option>
             <option value="Agent">Agent</option>
          </select></td>
        </tr>
        <tr>
          <td><label>Quanity:</label></td>
          <td><input name="qty" type="text" value="1" size="3" maxlength="3" /></td>
        </tr>
    </table>
    <p><input name="btnCalculate" type="button" value="Calculate" onclick="calcball(ball.value, qty.value)" /></p>|
    </form>
    </body>
    </html>

    kpac

    • Web moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: java script help
    « Reply #1 on: May 03, 2009, 02:44:11 AM »
    In the <head>, replace the old script with this:

    Code: [Select]
    <script type="text/javascript">
    function calcball(ball, qty){
         var ball = document.getElementsByName("ball").selectedIndex;
         var gty = document.getElementsByName("qty").value;
         var price = 0.00;
         msg = "";
         if (ball == "The Cell") price = 150.00;
         else if (ball == "Cell Pearl") price = 200.00;
         else if (ball == "Cell Rouge") price = 220.00;
         else if (ball == "Agent") price = 160.00;

         price *= qty;
         msg += "Total price is:  $" + price;
         alert(msg);|
    }
    </script>

    garyg

      Topic Starter


      Newbie

      Re: java script help
      « Reply #2 on: May 03, 2009, 08:30:47 AM »
      KPAC,

      Thanks for adding the two lines of var.  I tried it and still came up with an object error.  The error I think is at the onclick line.  Am I calling for the object corectly?