<script>
document.write('<table width="100%" border="1">');
//-----------------------------------------------------------------------
document.write('<tr>');
document.write('<td><b>A:</b></td>');
document.write('<td><input type="text" id="a" value=""></td>');
document.write('</tr>');
//-----------------------------------------------------------------------
document.write('<tr>');
document.write('<td><b>B:</b></td>');
document.write('<td><input type="text" id="b" value=""></td>');
document.write('</tr>');
//-----------------------------------------------------------------------
document.write('<tr>');
document.write('<td><b>Operacion:</b></td>');
</script>
<td><select id="Operacion" >
<option value="1" selected> suma </option>
<option value="2"> resta </option>
<option value="3"> multiplicacion </option>
<option value="4"> division </option>
</select></td>'
</tr>'
<script type="text/javascript">
//-----------------------------------------------------------------------
document.write('<tr>');
document.write('<td><b>A:</b></td>');
document.write('<td><input type="button" value="Calcular" onClick="calcular()"></td>');
document.write('</tr>');
//-----------------------------------------------------------------------
document.write('</table>');
function calcular(){
a = document.getElementById("a").value;
b = document.getElementById("b").value;
opera = document.getElementById("Operacion").value;
if (opera==1) {
alert(parseFloat(a)+parseFloat(b));
}
if (opera==2) {
alert(parseFloat(a)-parseFloat(b));
}
if (opera==3) {
alert(parseFloat(a)*parseFloat(b));
}
if (opera==4) {
if (a==0) {
alert(error);
}
else{
if(b==0){
alert(error);
}
else{
alert(parseFloat(a)/parseFloat(b));
}
}
No hay comentarios.:
Publicar un comentario