You are not logged in.
<html>
<head>
<title>StupidEvaluation</title>
<script type="text/javascript">
<!--
var myresult = "";
function EvalInput(input) {
var result = eval(input);
myresult = result;
alert(result);
}
// -->
</script>
</head>
<body>
<center>
<form name="calcform">
<input name="calcbox" type=text><br>
<!-- Run function -->
<input name="calcbtn" type=button value="Calculate!"
onclick="EvalInput(calcform.calcbox.value);">
<input name="calcdel" type=reset value="Erase"><br>
<!-- Get result from function somehow and display somewhere -->
<script type="text/javascript">
document.write(myresult);
</script>
</form>
</center>
</body>
</html>
<!-- vim:set ts=2 sw=2 et: -->
I'm facing two problems with this:
1) I can't seem to figure out how one would actually print a result produced by a function from an onclick event, instead of using some popup function like alert().
2) It appears impossible to get the Return/Enter key to act like a click. I've tried both submit and manually matching the keycode but these actually clear the input box after the function has finished running - I don't want that.
I need real, proper pen and paper for this.
Offline
try something like this, it should cover both questions:
<html>
<input type="text" id="myText">
<input type="button" id="myButton" value="Pressme!">
<div id="status"></div>
<script type="text/javascript">
myButton.onkeypress = function(e) {
myText.value = e.keyCode;
document.getElementById('status').innerHTML = 'Succes!';
}
</script>
</html>
ᶘ ᵒᴥᵒᶅ
Offline
1) I can't seem to figure out how one would actually print a result produced by a function from an onclick event, instead of using some popup function like alert().
You should use the DOM.
2) It appears impossible to get the Return/Enter key to act like a click. I've tried both submit and manually matching the keycode but these actually clear the input box after the function has finished running - I don't want that.
Your "Calculate!" button should be of type="submit" and then preform the calculation on the form's "submit" event.
Offline
Hey thanks guys..I've gone on to do it all from scratch, I'm trying to see what's possible and maybe I'll dive into MathML =p
N30N: That's exactly what I tried and didn't like, because it cleared the input upon submit.
I need real, proper pen and paper for this.
Offline
N30N: That's exactly what I tried and didn't like, because it cleared the input upon submit.
Call the preventDefault event method (and also set the returnValue property to false if your supporting IE's non standardness) to stop that.
Offline
You are one awesome archer
I need real, proper pen and paper for this.
Offline