www.webdeveloper.com
Results 1 to 4 of 4

Thread: I Cannot see why this wont work

  1. #1
    Join Date
    May 2010
    Posts
    2

    Exclamation I Cannot see why this wont work

    probably something ridiculous but i think I have snow goggles on as i just came from an exam.... and have been looking at it since. Can anyone see why this is not computing and displaying the alert..... Its ridiculously simple code


    <%--
    Document : Q1 Summer Exam
    Created on : 10-May-2010, 15:02:26
    Author : k00-----
    --%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <form name="form1" action="">
    <p> Customer Name: <input type="text" id="name"></p>
    <table border="0">
    <tr>
    <th>Product</th>
    <th>Price </th>
    <th>Quantity</th>
    </tr>
    <tr>
    <td>Keyboard</td>
    <td>40</td>
    <td><input type="text" id="keyboard" value=""</td>
    </tr>
    <tr>
    <td>Mouse</td>
    <td>24</td>
    <td><input type="text" id="mouse" value=""</td>
    </tr>
    <tr>
    <td>Hard Disk</td>
    <td>55</td>
    <td><input type="text" id="hardDisk" value=""</td>
    </tr>
    <tr>
    <td>Usb Key</td>
    <td>6</td>
    <td><input type="text" id="usb" value=""</td>
    </tr>
    <tr>
    <td>Visa<input type="radio" name="pay" id="Visa" </td>
    <td>MasterCard<input type="radio" name="pay" id="Mastercard" </td>
    <td>PayPal<input type="radio" name="pay" id="Paypal"</td>
    </tr>
    <tr>
    <td><input type="submit" value="Submit" onclick="calculateTotal()"</td>
    <td><input type="reset" value="Reset" </td>
    </tr>



    <script type="text/javascript">
    function calculateTotal(){
    name=document.form1.getElementById(name)
    product1=document.form1.getElementById(keyboard*40)
    product2=document.form1.getElementById(mouse*24)
    product3=document.form1.getElementById(hardDisk*55)
    product4=document.form1.getElementById(usb*6)
    total=product1+product2+product3+product4
    if(total==null){
    alert("Please enter a name, a payment method and your quantity for product")

    }
    else

    alert("Customer name: "+name+", Your Total Cost Is "+total+(total/100*10))
    }
    </script>
    </table>
    </form>
    </body>
    </html>

    sorry if its embarrasingly simple.... I am a student!

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    to start,
    product1=document.form1.getElementById(keyboard*40)

    those lines are looking for variables when you need a string
    the way it sis, the way the machine reads it is var keyboard multiplied by 40

  3. #3
    Join Date
    May 2010
    Posts
    2

    Question s

    does it not get the string value when getElementById is made equal to that variable?
    ie: product1=document.getElementById((keyboard)*40)

    product one is equal to the element with id of keyboard and a value of whatever the user enters?

    thats what I was trying to do anyway....

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    product1=document.getElementById('keyboard').value*40;
    At least 98% of internet users' DNA is identical to that of chimpanzees

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