By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

Question on math.pow function

P: 4
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:


Expand|Select|Wrap|Line Numbers
  1. "http://www.w3.org/TR/html4/strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4. <script language="JavaScript">
  5. function math.pow(number,2)
  6. </script>
  7.  
  8. <form name="square" action="#">
  9. <input type="text" name="number">
  10. <input type="button" value="compute" onclick="process()">
  11. <input type="text" name="result">
  12. </form>
  13. </html>
Jul 8 '13 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,364
Please use code tags when posting code.

You have no function named process.
Jul 8 '13 #2

P: 4
I made some edits, including a process function, however the code still does not work.

I am new to JS - any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <script language="JavaScript">
  6. <!-- 
  7. function process()
  8. {
  9.    var formObj = document.getElementById();
  10.    var number = formObj.number.value;
  11.    {
  12.       formObj.number.value = Math.pow(number,2); break;
  13.    }
  14.  
  15. //  -->
  16. </script>
  17. </head>
  18. <form name="square" action="#">
  19. <input type="text" name="number">
  20. <input type="button" value="compute" onclick="process()">
  21. <input type="text" name="result">
  22. </form>
  23. </html>    
  24.  
  25.  
Jul 9 '13 #3

Rabbit
Expert Mod 10K+
P: 12,364
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.
Jul 9 '13 #4

Dormilich
Expert Mod 5K+
P: 8,639
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()).
Jul 9 '13 #5

Post your reply

Sign in to post your reply or Sign up for a free account.