Thread: how to code
View Single Post
Old 01-30-2013, 05:57 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
This is by no means elegant and probable not what you meant by menu (that's the problem with not giving some code to start with) And worst it probable wont be accepted, but I had some free time.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style type="text/css">
textarea
{
	resize:none;
	height:20px;
	float:left;
}
button
{
	display: list-item;
	list-style: none;
}
</style>
</head>
<body onload="document.getElementById('first').focus();">
<div id="text">Enter a number. Then tab</div>
<textarea id="first" cols="3" maxlength="5" tabindex=1></textarea>
<div id="sign" style="height:20px;width:30px;text-align:middle;padding-left:23px;float:left;">?</div>
<textarea id="second" cols="3" maxlength="5" tabindex=2></textarea>
<div id="equal" style="height:20px;width:30px;text-align:center; float:left;">=</div>
<textarea id="answer" cols="3" maxlength="5" tabindex=-1></textarea>
<br /><br />
<button onclick="action('Sum');" tabindex=3>Sum</button>
<button onclick="action('Difference');" tabindex=4>difference</button>
<button onclick="action('Product');" tabindex=5>product</button>
<button onclick="action('Quotient');" tabindex=6>quotient</button>
<script type="text/javascript">
function action(control)
{
	if(control == 'Sum')
	{
		document.getElementById('sign').innerHTML = "+";
		document.getElementById('answer').value=Number(document.getElementById('first').value) + Number(document.getElementById('second').value);
	}
	else if(control == 'Difference')
	{
		document.getElementById('sign').innerHTML = "-";
		document.getElementById('answer').value=Number(document.getElementById('first').value) - Number(document.getElementById('second').value);
	}
	else if(control == 'Product')
	{
		document.getElementById('sign').innerHTML = "*";
		document.getElementById('answer').value=Number(document.getElementById('first').value) * Number(document.getElementById('second').value);
	}
	else if(control == 'Quotient')
	{
		document.getElementById('sign').innerHTML = "/";
		document.getElementById('answer').value=Number(document.getElementById('first').value) / Number(document.getElementById('second').value);
	}
}
</script>
</body>
</html>
sunfighter is offline   Reply With Quote