Results 1 to 4 of 4

Thread: Need Help With My Script

  1. #1
    Join Date
    Mar 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help With My Script

    Hi everyone,
    I am tarun, and i am very new to javascript coding. Recently i have been working on this one code that wuould convret and tell you what you wud weigh on othe planets when the visiotor gives you his weight in an input box. so far i have this much and it doesnt seem to work, i think i know there is sumthing wrong with the onClick button,,but anywyas can any one please tell me whats wrong with it. Here is the code


    <html>
    <head>
    <title> Find your weight on other planets </title>

    <script>

    function candy (form.ans.value)
    {
    a=eval(form.w.value)
    b=(10*a*1.66)/10
    form.moon.value=b
    }

    </script>


    </head>


    <body>

    <form name=form>

    <table>
    <tr>
    <td> Enter your weight here: <input type=text value="" name=w> </td>
    </tr>
    <tr>
    <td> Click here to see what you weigh on other planets: <input type=button value="Click for your results" onClick="ans(this.form)"> </td>
    </tr>
    <tr>
    <td> Click here to reset: <input type=reset value="Reset"><p> </td>
    </tr>
    <tr>
    <td> Moon: <input type=text value="" name=moon> </td>
    </tr>

    </table>

    </form>

    </body>
    </html>


    any help would be greatly appreciated!!!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Change this:

    Code:
    onClick="ans(this.form)"
    to this:

    Code:
    onClick="candy(this.form)"
    Then in your code (between the head tags), make the following changes in red:

    Code:
    <script>
    
    function candy(theForm)
    {
    
    a= theForm.w.value
    b=(10*a*1.66)/10
    theForm.moon.value=b
    }
    
    </script>
    That should work for you. Hope this helps.
    Last edited by thetestingsite; 03-10-2007 at 05:15 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You cannot have the . character as a parameter for a function as you have done it. Try:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title> Find your weight on other planets </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function ans (form)
    {
    a=form.w.value
    b=(10*a*1.66)/10 
    form.moon.value=b;
    }
    </script>
    </head>
    <body>
    <form action="#">
    <table>
    <tr>
    <td> Enter your weight here: <input type="text" value="" name="w"> </td>
    </tr>
    <tr>
    <td> Click here to see what you weigh on other planets: <input type="button" value="Click for your results" onclick="ans(this.form)"> </td>
    </tr>
    <tr> 
    <td> Click here to reset: <input type="reset" value="Reset"><p> </td>
    </tr>
    <tr>
    <td> Moon: <input type="text" value="" name="moon"> </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    BTW, your math is wrong for converting to 1/6 g's, it should be:

    Code:
    b=a*.66;
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •