www.webdeveloper.com
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2012
    Posts
    2

    Please help this beginner

    I am trying to get a simple result. I want the total to appear in the alert box and it does not. Please help. The code is below:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script language="JavaScript" type="javascript">
    function sum();
    {var a="";
    var b="";
    result(a+b)
    alert("Total is =" +sum());}
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <p>I hope this works!!!</p>
    <input type="text" name="a" />
    <input type="text" name="b" />
    <input type="button" value="Add" onclick="sum();" style="width: 55px" />

    </form>
    </body>
    </html>

    Thanks for your help.

    ps

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    6,949

    Lightbulb

    Numerous errors. Compare this working version to your original.
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <title>Untitled</title>
    <script type="text/javascript">
    function sum() {
     var a=Number(document.myForm.a.value);
     var b=Number(document.myForm.b.value);
     alert("Total is = " +(a+b));
    }
    </script>
    </head>
    <body>
    <form name="myForm" action="" method="post" onsubmit="return false">
    <p>I hope this works!!!</p>
    <input type="text" name="a" />
    <input type="text" name="b" />
    <input type="button" value="Add" onclick="sum();" style="width: 55px" />
    </form>
    </body>
    </html>
    If you put your script between [ code] and [ /code] tags (without the spaces)
    it makes it easier to read, copy and test for other forum members.

  3. #3
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,040
    A good sandbox to play with your scripts is JSFiddle.net

    I love that tool!

    http://jsfiddle.net/QZSQX/

  4. #4
    Join Date
    Aug 2012
    Posts
    2
    Thank you!!!!

Thread Information

Users Browsing this Thread

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

     

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
HTML5 Development Center



Recent Articles