Question on math.pow function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • riplus0623
    New Member
    • Jul 2013
    • 4

    Question on math.pow function

    I am working on a problem and have been trying for several hours to get this to work. Basically, the form language was provided - I need to input JS code to produce the square root of the number that is inputted by the user and display it on the form.

    The form produces fine - the program not computing a result is my issue. Any help is appreciated. Code I have produced is as follows:


    Code:
    "http://www.w3.org/TR/html4/strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <script language="JavaScript">
    function math.pow(number,2)
    </script>
    
    <form name="square" action="#">
    <input type="text" name="number">
    <input type="button" value="compute" onclick="process()">
    <input type="text" name="result">
    </form>
    </html>
    Last edited by Rabbit; Jul 8 '13, 05:14 AM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    You have no function named process.

    Comment

    • riplus0623
      New Member
      • Jul 2013
      • 4

      #3
      I made some edits, including a process function, however the code still does not work.

      I am new to JS - any help is appreciated.

      Code:
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <script language="JavaScript">
      <!-- 
      function process()
      {
         var formObj = document.getElementById();
         var number = formObj.number.value;
         {
            formObj.number.value = Math.pow(number,2); break;
         }
      } 
      
      //  -->
      </script>
      </head>
      <form name="square" action="#">
      <input type="text" name="number">
      <input type="button" value="compute" onclick="process()">
      <input type="text" name="result">
      </form>
      </html>

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You didn't tell getElementById which id to get. Also, your form has no id. So you won't be able to get it anyways unless you give it one.
        Last edited by Rabbit; Jul 9 '13, 02:14 AM.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I need to input JS code to produce the square root of the number that is inputted
          Math.pow(x, 2) produces the square of x, not its square root (that would be Math.sqrt()).

          Comment

          Working...