Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-13-2008, 10:31 AM
Member
 
Join Date: Apr 2008
Posts: 1
aapanju is on a distinguished road
Java Calculator
Can any 1 get this to work and tell me where I am going wrong ... kauz now im totally lost.
Thankz


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Web Calculator</title>



<style type="text/css">
body
{
font-family: Arial;
}
div.table
{
font-weight: bold;
}
legend
{
color: #0000ff;
font-weight: bold;
font-size: xx-large;
}
</style>

<style type="text/javascript">

function gettheresult()
{

var FirstNumber = document.getElementById("firstnumber").value;
var SecondNumber = document.getElementById("secondnumber").value;
var Option = document.getElementById("pick").value;


}

</style>

</head>

<body>
<form>
<fieldset title="web calculator">
<legend>My Calculator</legend>

<div class="table">
<table>
<tr>
<td>First Number:</td>
<td><input type="text" size="10" name="first" id="firstnumber" /></td>
</tr>
<br />
<tr>
<td>Second Number:</td>
<td><input type="text" size="10" name="second" id="secondnumber" /></td>
</tr>
<br />
<tr>
<td>Result:</td>
<td><input type="text" size="10" name="result" id="resultofboth" /></td>
</tr>
<br />




<td>
<select id="pick">
<option value="+">ADD</option>

<option value="firstnumber-secondnumber">SUBTRACT</option>

<option value="firstnumber*secondnumber">MULTIPLY</option>

<option value="firstnumber/secondnumber">DIVIDE</option>

</select>

<input type="reset">

</td>

<td><button onclick="theresult">Calculate</button></td>


</table>

</div>


</fieldset>

</form>


</body>




</html>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-13-2008, 06:34 PM
bobleny's Avatar
Member
 
Join Date: Apr 2008
Posts: 36
bobleny is on a distinguished road
OK, first off, this is a Java forum, not a JavaScript forum. There is a huge difference! Java vs. JavaScript

Second, you want to use the "script" tag, not the "style" tag.
Third, your button isn't calling the "gettheresult()" function.
Fourth, you can't preform the operation while setting it equal to Option.
Fifth, your trying to add two strings, that is "6"+"4" will equal 64.
Sixth, you haven't told javascript to put the answer in the result box.
Seventh, even if you do get the result to display in the box, the way you are scripting this, the page will simply refresh and the result will be gone.

As far as what you did wrong, that is about it...

What you should do, is use a form to submit the data to javascript. You can then use javascript to stop the page from reloading.

Change your pick options to a simple word, letter, or symbol to represent the option. Then use an ifelse statement to figure out the operation.

Then use the pasreInt() function to to convert your string value into an integer value.

Preform the operation, and place the result in the result box.

Not to hard, your just going at it wrong...
__________________
--
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
--
Cheer up, the worst has yet to come...

Last edited by bobleny : 04-17-2008 at 05:25 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 04:46 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 524
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Honestly correct!!! i agree...

regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 06:33 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,042
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by bobleny View Post
OK, first off, this is a Java forum, not a JavaScript forum. There is a huge difference! Java vs. JavaScript
Thanks for the link bobleny. Lots of people really mess-up with Java and JavaScript. Since there is a word Java, they think both are same.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java calculator decimal cart1443 New To Java 2 04-16-2008 02:19 PM
calculator not working Renegade85 New To Java 5 03-10-2008 04:27 PM
Create a Calculator in Java Albert New To Java 2 07-04-2007 09:01 AM
Swing Calculator nemo AWT / Swing 1 05-28-2007 12:07 PM


All times are GMT +3. The time now is 10:51 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org