Hola
lulavirgi.
Te paso un esbozo de lo que haría yo en este caso. No se si es muy pronto para hablar de
this pero bueno, he ahorrado muchas funciones en tu código.
Código PHP:
<script type="text/javascript">
<!--
function borrarled (){
document.form1.led.value="";
}
function borrarx() {
document.form1.led.value=document.form1.led.value.slice(0,-1);
}
function ponContenido(btn) {
document.form1.led.value += btn.value;
}
function resultado() {
document.form1.led.value = eval( document.form1.led.value );
}
// -->
</script>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="led" maxlength="8"/> <br><br>
<input type="button" value="1" onclick="ponContenido(this);">
<input type="button" value="2" onclick="ponContenido(this);">
<input type="button" value="3" onclick="ponContenido(this);">
<input type="button" value="C" onclick="borrarled();"><br><br>
<input type="button" value="4" onclick="ponContenido(this);">
<input type="button" value="5" onclick="ponContenido(this);">
<input type="button" value="6" onclick="ponContenido(this);">
<input type="button" value="<" onclick="borrarx();"> <br><br>
<input type="button" value="7" onclick="ponContenido(this);">
<input type="button" value="8" onclick="ponContenido(this);">
<input type="button" value="9" onclick="ponContenido(this);">
<input type="button" value="0" onclick="ponContenido(this);"> <br><br>
<input type="button" value="+" onclick="ponContenido(this);">
<input type="button" value="-" onclick="ponContenido(this);">
<input type="button" value="*" onclick="ponContenido(this);">
<input type="button" value="/" onclick="ponContenido(this);"> <br><br>
<input type="button" value=" = " onclick="resultado()">
</form>
Lo del
eval() no es un método muy fiable (porque te pueden ejecutar cualquier cosa) pero funciona muy bien siempre que se escriba algo coherente.
Un saludo