Jump to content

Javascript Sqrt help

Featured Replies

I understand the rest of the Calculator and I know HTML + CSS, but I have no idea how to add a sqrt button, can anybody help the code is below the line where I tried is in red:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
input {text-align:center;}
table {text-align:center;position:absolute;left:550px;top:150px;}
body {background-color:black;}
</style>
</head>
<body>
<FORM NAME="Calc">
<TABLE BORDER=4>
<TR>
<TD>
<INPUT TYPE="text" NAME="Input" Size="16">
<br>
</td>
</tr>
<TR>
<TD>
<INPUT TYPE="button" NAME="one" VALUE=" 1 " OnClick="Calc.Input.value += '1'">
<INPUT TYPE="button" NAME="two" VALUE=" 2 " OnCLick="Calc.Input.value += '2'">
<INPUT TYPE="button" NAME="three" VALUE=" 3 " OnClick="Calc.Input.value += '3'">
<INPUT TYPE="button" NAME="plus" VALUE=" + " OnClick="Calc.Input.value += ' + '">
<br>
<INPUT TYPE="button" NAME="four" VALUE=" 4 " OnClick="Calc.Input.value += '4'">
<INPUT TYPE="button" NAME="five" VALUE=" 5 " OnCLick="Calc.Input.value += '5'">
<INPUT TYPE="button" NAME="six" VALUE=" 6 " OnClick="Calc.Input.value += '6'">
<INPUT TYPE="button" NAME="minus" VALUE=" - " OnClick="Calc.Input.value += ' - '">
<br>
<INPUT TYPE="button" NAME="seven" VALUE=" 7 " OnClick="Calc.Input.value += '7'">
<INPUT TYPE="button" NAME="eight" VALUE=" 8 " OnCLick="Calc.Input.value += '8'">
<INPUT TYPE="button" NAME="nine" VALUE=" 9 " OnClick="Calc.Input.value += '9'">
<INPUT TYPE="button" NAME="times" VALUE=" x " OnClick="Calc.Input.value += ' * '">
<br>
<INPUT TYPE="button" NAME="clear" VALUE=" c " OnClick="Calc.Input.value = ''">
<INPUT TYPE="button" NAME="zero" VALUE=" 0 " OnClick="Calc.Input.value += '0'">
<INPUT TYPE="button" NAME="Enter" VALUE=" = " OnClick="Calc.Input.value = eval(Calc.Input.value)">
<INPUT TYPE="button" NAME="div" VALUE=" / " OnClick="Calc.Input.value += ' / '">
<br>
<input type="button" name="sqrt" value="sqrt" OnClick="Calc.input.value += 'sqrt'">
</td>
</tr>
</table>
</form>
</p>
</body>
</html>


Also, I am well aware of the math.sqrt(x) function

No one has responded to your post in several hours. I am unsure whether I can help, but will try.

 

Are you asking how to get a square root symbol displayed by HTML?

  • Author

Not at all, I need to use the function in a table, and in a button. But, that would be nice to know how to add it....

Edited by howlingmadpanda

You could, for a start, ask yourself why you expect taking the square root to be expressed with a "+=". The "+=", as you may notice, is mainly used in cases where a new digit is attached to the end of your input (which is not what taking a square root does). Hint: Have a closer look at "clear" and "enter".

  • Author

I know, I understand the Calculator and the square root function, I need a function that I can use for Onclick=function() and use the square root I have already tried several

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.