i dont know how to link the Digitadd() function (javascript code) with button 1 (html code) . there also flaws with js code could anyone help me from this.
codepen link: http://codepen.io/indian46/pen/egZKMz
HTML CODE
Calculator
|
|
|
|
</tr>
<tr>
<td><input type="button" class="button" value="4" Onclick="calculator.boxdisplay.value+='4'" > </td>
<td><input type="button" class="button" value="5" Onclick="calculator.boxdisplay.value+='5'"> </td>
<td><input type="button" class="button" value="6" Onclick="calculator.boxdisplay.value+='6'"> </td>
</tr>
<tr>
<td><input type="button" class="button" value="7"Onclick="calculator.boxdisplay.value+='7'"> </td>
<td><input type="button" class="button" value="8" Onclick="calculator.boxdisplay.value+='8'"> </td>
<td><input type="button" class="button" value="9" Onclick="calculator.boxdisplay.value+='9'"> </td>
</tr>
<tr>
<td><input type="button" class="button" value="+/-" Onclick="calculator.boxdisplay.value+='1'"> </td>
<td><input type="button" class="button" value="0" Onclick="calculator.boxdisplay.value+='0'"> </td>
<td><input type="button" class="button" value="." Onclick="Dot()"> </td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td><input type="button" class="button" value="C"></td>
<td><input type="button" class="button" value="AC"></td>
</tr>
<tr>
<td><input type="button" class="button" value="*" Onclick="calculator.boxdisplay.value+='*'"></td>
<td><input type="button" class="button" value="/" Onclick="calculator.boxdisplay.value+='/'"></td>
</tr>
<tr>
<td><input type="button" class="button" value="+" Onclick="calculator.boxdisplay.value+='+'"></td>
<td><input type="button" class="button" value="-" Onclick="calculator.boxdisplay.value+='-'"></td>
</tr>
<tr>
<td><input type="button" class="button" value="=" Onclick="calculator.boxdisplay.value=eval(calculator.boxdisplay.value)"></td>
<td><input type="button" class="button" value="EXP"></td>
</tr>
</td>
</tr>
</table>
</form>
css code
body
{
background-color:black;
color:red;
font-family:serif;
border:none;
}
.box
{
text-align:center;
margin:100px 20px 40px 200px;
}
.button
{
width:100%;
background-color:#4CAF50;
border:none;
color:white;
padding:15px 32px;
text-decoration:none;
display:inline-block;
font-size:20px;
margin:4px 2px;
cursor:pointer;
}
table
{
width:25%;
border:black;
}
th
{
height:50px;
}
th,td
{
padding:5px;
text-align:center;
}
.table1
{
/* border:8px solid #FFFFFF; */
border-radius:10px 10px 10px 10px;
background-color:#008CBA;
box-shadow:10px 10px 5px 30px #008CBA;
border:none;
}
.boxd
{
margin:4px 4px 24px 4px;
}
javascript code
$(document).ready(function()
{
Defvalue=“0”;
Cvalue=“0”;
Operation=0;
Maximumlength=25;
function Digitadd(numb)
{
if(Cvalue.length > Maximumlength)
{
Cvalue=“Ouch your value is too long”;
}else
{
if( (eval(Cvalue)==0) && Cvalue.indexof(".")==-1 )
{
Cvalue=numb;
}else
{
Cvalue=Cvalue+numb;
};
};
document.calculator.boxdisplay.value=Cvalue;
}
function Dot()
{
if(Cvalue.length==0)
{
Cvalue=“0.”;
}else
{
if(Cvalue.indexOf(".")==-1)
{
Cvalue=Cvalue+".";
};
};
document.calculator.boxdisplay.value(Cvalue);
}
});
|