Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2013, 12:20 PM   PM User | #1
kittyluv
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kittyluv is an unknown quantity at this point
Thumbs down how to code

Please can someone help me! I am trying to make a code (menu) that inputs 2 numbers and at the user's option finds the sum, difference, product or quotient. Is there anyone who can help?
kittyluv is offline   Reply With Quote
Old 01-30-2013, 12:33 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Sounds like homework!

As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 01-30-2013, 05:57 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,399
Thanks: 18
Thanked 352 Times in 351 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
Reply

Bookmarks

Tags
need help on a code

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:24 AM.


Advertisement
Log in to turn off these ads.