number confusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • student33
    New Member
    • Feb 2007
    • 3

    #1

    number confusion

    below is the javascript that works ok. but i was wanting to assign a variable directly
    and as yet i can not can any on tell me what i am doing wrong surround area in question with caps

    [HTML]<script language="JavaS cript">
    function calculateArea(n um1)
    {
    num2 = num1*2
    return num2
    }
    </script>
    </head>
    <body>
    <form name ="myForm">[/HTML]

    THE LINE BELOW HERE IS WHAT I WANT TO REPLACE

    put number in this box[HTML]<input type="text" name="num1" value="">
    [/HTML]
    WHAT I WANT IS SOMETHING LIKE THIS var num1=5; but it does not work?



    [HTML]<br><br><br>
    <input type="button" value="clik to multiply number by 2"
    onClick ="document.myFo rm.num2.value = calculateArea(n um1.value)">
    <br/><br><br>

    number * 2 will appear here <input name="num2" value="">

    </form>
    </body> </html>[/HTML]
    Last edited by acoder; Feb 27 '07, 09:32 AM. Reason: Code in tags
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    I'm not sure what you ask.
    Do you want to set num1 directly after user input?

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Just put 5 into the value attribute.
      Code:
      <input type="text" name="num1" value="5">
      The problem you have is accessing the field value. Use:
      Code:
      var num1 = document.myForm.num1.value;

      Comment

      Working...