Simple Calculator - Where To Add ParseInt Function
Oct 18, 2009
I need to create a simple calculator in Java. Below is what I have so far; it is not working currently and I'm not sure why. I also needed to add the parseInt function somewhere in the code but I'm not sure where.
import java.util.Scanner;
public class CalcDemo {
public static void main(String[] args){
}
private int valueA;
private int valueB;
private String operator;
private char operatorA;
public int getvalueA() {
return valueA;
} .....
I'm getting started at javascript and jQuery, I want to make a calculator for my services, for example, checking a box will add value to a total.For example theres a textbox that asks how much gallons of paint will be used, the value of each gallon is 30 dollars, so the user can write for example 2 on the input and a div will output 60. I think that would be made with .change(), but in the demo of the documentations appears a selection list, and I can't figure out how to make an input work like that.
I am wanting to create a simple dynamic calculator.That when a radio button in the HTML <form> is selected is adds a value to the calculation and displays it live below.For example the select a package:
[] one [] two [] three
then they choose an extra's they want to add on:
[] one [] two [] three [] four
and below it displays this:
[ The name of package selected + value of it in (�) ] + The value of all the add ons they have selected in (�)
I keep getting a NaN on this form-based calculator I am trying to make... I can't figure out what I am doing wrong. Any input, or in this case "output", Here is the code:
Code: <script type="text/javascript"> function calculateBudget() {
I am trying to come up with an instant price quote calculator in javascript.it would be a simple one with only three fields:
"label" -Number of Shirts "label" -Number of Colors on Front "label" -Number of Colors on Back "button" calculate total "results" total: $xx per bagxx
total price would decrease based on the number of shirts (more volume) / increase based on the number of colors both front and back.
something i found online that is 100% what i want:[URL]i am not too familiar with javascript. ok tinkering with jquery but that's it.i am obviously not asking anyone to work for free but if someone could point me to a semblance of a solution, some code, something online that i could modify etc. i would love to learn javascript in the process and ideally come up with a working version of the calculator.
i tried to work with the .js from that website but it calls in some qq2.php page. so i haven't been able to replicate the solution. plus, i would assume that their price structure would be different than mine.
The exercise problem is to "MODIFY the code in the "calculate_click" event so interest is added to future value just once each year for the number of years that they were entered by the user". The calculation as you see it below assumes an amount is invested MONTHLY (not just once), and the interest is calculated accordingly. This is what I think the problem is trying to calculate: using a $100 one time investment at 10% interest (compounded once annually) for one year = $110 as the future value. For two years, the future value should equal $121 (110 + (110*.10)). Okay, if my math is wrong, let me know. This is what I'm trying to get it to match to.
I have been able to modify the calculate_click function to compound the interest annually (it does it monthly now). Cool. I cannot get it to stop adding $100 annually. See my math above? I think that's the answer. My manipulation of the code yields $110 for the first year, $231 for the second year, etc. The $231 is incorrect cuz it adds an extra $100. See, this is a simple interest calculator I can't figure out! The original code is below that calculates the investment as a monthly investment as opposed to one-time. To avoid confusion, I did not include any of my modifications. But yeah. I know that the major culprit is how the "for" loop is being executed. I've highlighted where I think the code needs to be changed, but I haven't changed it here. Note the first function is a shortcut to execute getElementbyID.
The Code: var $ = function (id) { return document.getElementById(id); } var calculate_click = function () { var investment = parseFloat( $("investment").value ); var annualRate = parseFloat( $("rate").value ); var years = parseInt( $("years").value ); $("futureValue").value = ""; .....
This is a calculator that calculates how much a user can earn from their referrals depending on the user's Level & Member type. It's supposed to be updating live (onChange) when the user types in new values in the fields, but nothing is happening. [URL].
Code: <html> <head> <script type="text/javascript"> function calculate(){ // eval makes the script know the value is a number, and not text var myLevel = eval(document.earningsform.level.value); var memberType = eval(document.earningsform.type.value); var viewed = eval(document.earningsform.viewed.value); .....
function shout() { if (isNaN(document.form1.entry.value)==true) { alert("please only enter numbers for an answer")} else { alert("the new number is: "+(+document.form1.entry.value+5))} }
also what would be the correct structure as to make the script more legible to regular and proficient writers of JS?
I'm trying to write a function that does a simple math function between some textfields.
There are 4 variables : Unit price, Discount, Quantity and Total
Unit price is a fixed variable.
Discount, Quantity and Total depend on the fixed variable and also on the values of eachother. (ie : if qty=2 then total=2xUnit Price) etc...
I want to be able to show the changing values in real time.
So if I have 3 textfields and I change qty, I want it to update Total based on the discount and the qty. If I update discount, I want to update Total based on qty and discount.
I'm guessing I would have to write three functions and call each one from their respective textfields.
How to write a function, and call it so that passes the unit price to the funtion, gets the values of all of the textfields and then changes them all to their new values?
I am trying to make a simple trim function but this doesnt works. function tr(input){ var i; var str; for(i=0; i<input.length-1; i++){ if(text.charAt(i)==" "){ str+=""+text.charAt(i) } return str }}
I have a simple function defined on my page in the script section that should put me in a div named "apDiv4" a text when i press the down arrow in a text input called 'search2'. But it does nothing.
Here's the function:
And here is where i call it:
Why this doesn't work? I've tried onkeydown= "KeyCheck()" too.
I am a Javascript newbie and I'm trying to implement a very simple form validation function, but for some reason it won't work. I must be doing something fundamentally wrong here. Maybe somebody can hint me into the right direction? My code looks like so:
function validate_form () { valid = true; var re = new RegExp(); re.compile("[A-Za-z0-9._-]+@[^.]+..+"); if ((document.form.author_name.value == "") || (document.form.author_email.value == "") || (!re.test(document.form.author_email.value)) || (document.form.author_message.value == "")) { alert ("Please fill in all required fields."); valid = false; } return valid; }
The tricky bit is the email validation using the regular expression. Apart from that it all works.
Don Gosselin's JavaScript Fourth Edition is a tiresome read and I have been unable to put together the necessary tools that Don teaches to find the answers that I want to make the following function work.
function calculate() var shipping = 0; var total = 0; { if (document.forms[0].hand_tool.value != document.forms[0].hand_tool.value == true) (document.forms[0]item1.value == 20); {
I am doing a simple slidetoggle with a click function. Meaning I am basically sliding a div (content) into nothing with another div (button) using a click event. This works all fine and dandy but now here is the problem.. I want to change the class of the div(button) so that I may show a different background image depending on the state of the open or closed content div.
Here is the code so far... $(document).ready(function() { $('.Button').click(function() { $('.Content').slideToggle('normal'); if($(this).next().is(':hidden') == false) { $(this).addClass('off'); alert ('You should see See More button.'); }}); Then obviously I have CSS that has the classes I need including an "on" class that I could not get to fire.
I am trying to write a simple javascript function that locates a parameter in a url, if it is present, and replace it with a different value. Here's my code:
function setParam(url,param,value) { var a = '&'+param+'=d+'; var new_url = url.replace(new RegExp(a), ''); new_url = new_url + '&'+param+'='+value; return new_url; }
The problem is, it doesn't work. It adds the new param, value pair to the old url, but the old param isn't replaced. What do I need to do here to make this work?
I am trying to do a simple echo onclick, but despite what I try to do, it shows no errors, but won't work. I've tried things like: echo "<div onclick="alert('test');">t</div>"; echo '<div onclick="alert('test');">t</div>'; But just can't seem to get it to work right. I'm trying to do this on a script that is being eval on the ajax request. Thus I'm having problems placing the ',", marks.
As part of a school project I had the main body of text at 11px, some people could read it, some couldn't, and so I created a zoom function. Unlike the normal zoom functions in JS or the browser's own zoom, which increase the size of everything thus throwing some areas out of proportion, mine only increases the size of the main body of text.
(using php tags to get code highlighting)
<table> <tr><script type="text/javascript"> var px = new Array(11,12,13,14,15,16,17,18,19,20,21,22,23); // insert your own numbers here, these are the font sizes - goes as higher or as low as you want. If the number is less than the original font size you have yourself a zoom-out function too. var size = 0; function do_change_down(elemID) {
if (size > 0) { size-- document.getElementById(elemID).style.fontSize = px[size] }
} function do_change_up(elemID) {
if (size < 12) { // number is how many elements in the px array. if there are more elements in the array, it will not use them all, it'll stop at that number, so make sure you increment it when you add more to the array. size++ document.getElementById(elemID).style.fontSize = px[size] }
in this instance I have the main content area with the id="text" - change the do_change_down('your_element_id'); and same for do_change_up accordingly to the text you want to be 'zoomed' in on..
As it says in the title, this is a very simple function but is also very effective.
I am really confused as similar code on Tizag web site works fine. Code: <script type="text/javascript"> function changeText(){ document.getElementById('boldStuff').innerHTML = 'Fred Flinstone'; }</script> <p>Welcome to the site <b id='boldStuff'>dude</b> </p> <input type='button' onclick='changeText()' value='Change Text'/>
I'm trying to graph line with a delay between each line drawn - my code is: var jg = new jsGraphics('Canvas'); jg.setColor('maroon'); jg.drawLine(40,130,80,120); setTimeout('jg.paint()',10000); jg.drawLine(80,120,120,110); setTimeout('jg.paint()',10000); Unfortunately it draws all the lines at the same time i.e the setTimeout function doesn't like the paint method.
I'm new to JavaScript, and have been playing around with a few simple functions to get going. However, I've hit a problem that I just can't fix, I'm trying to write a simple function to animate the collapse of a div using setTimeout (I know, jQuery does it a lot better), and it's gotten the best of me. The only error it's giving me now is
Code: missing ; before statement on line 25 but I can't see why. I assume it's something to do with my abuse of the setTimeout syntax (why does it insist that everthing is enclosed in quotes.I'm sure there are much better scripts than mine, and searching the forum I've come across Vic Phillips' fine specimen which mostly went over my head. But if I just wanted it to work I'd use jQuery - I'm more interested in why it's not working.
code is below. In addition to this I've also got an external script to compensate for browsers without getElementsByClass, but it should work in modern browsers up to the point where it doesn't!