Missing From Simple Calc() Function?

Nov 16, 2010

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); {

[Code]...

View 3 Replies


ADVERTISEMENT

Pass Input Array Value To Function To Calc Different Input Value

Jul 23, 2005

I have an array of input text boxes (txtDOBn) where n is created at
load. On the onchange event I want to calc the age and show in adjacent
input text boxes that are readonly and also arrays (an age calced for
each DOB entered). I was going to use the datediff function in vbscript
to do the calc. Code:

View 12 Replies View Related

Calc() Issue Not Going Over 2??

Sep 5, 2005

I have a javascript calculator that when you update a users level you click calculate and it updates there skill needed to reach the next level my problem is it only calculates as high as the number 2:

echo "<script langauage="javascript">
function calc() {
a = document.battle.newlevel.value;
b = 150;
c = document.battle.newskillneed.value;
answer = eval(a*a*b);
if(c>answer) {
document.battle.newskillneed.value = answer;
}
max.innerHTML = answer;
}
</script>";

Example: Level 2*(150 * Level 2) = 600 works fine but
Level 3*(150 * Level 3) = nothing why won't it work any higher its like there is a cap on how high it will go...

Also if I enter level 1 it comes up with 150 but if i put in level2 and press calculate it won't do anything but if i start out at level2 it works and then i move down to level 1 it works why won't it work moving up in numbers??

View 1 Replies View Related

Round Off This Calc To 2 Decimals?

Jan 3, 2010

First time user of Javascript and built an online calculator, trouble is I dont know where or how to code it so the answer ends with only 2 decimals

I have embedded code, Personally I think it's a miracle the darn thing works.:thumbsup: Link to page it's on [URL]...I have searched and read but after hours of trying stuff gave up.

<!--
function treevalue() {
document.volume.result.value=(((3.14159*((document.volume.radius.value)*(document.volume.radius.valu e)))*(document.volume.height.value))/3)*(document.volume.base.value)*(document.volume.e.value)*(document.volume.fv.value)*(document.volum e.l.value);

[Code]...

View 9 Replies View Related

Using Pull Downs And Calc Birthdate?

Apr 21, 2010

I am trying to use select options to get birthdate and calculate the age. I got the birthday with "birthDay = document.form1.selDate;" However i'm lost on the birthMonth and birthYear. I've looked at lots of examples. The birthMonth probably needs to be converted to integer, or use 1 thru 12 rather than Jan thru Dec. But birthYear i'd think would come back as a valid number. Is anyone familiar with this?

[Code]...

View 3 Replies View Related

Calc Subtotals And Total On Js/php Looped Form

Apr 14, 2005

I have an alteration to do on a multi-page form which was previous in use for single item selection and calculations only.

Now the form has to be altered to process multiple items. My difficulties lie in tackling the javascript calulations for a form that populates dynamically with as many items as the user has previously selects.

Item recordID's are POSTed to this form as an array. The array determines which item records are pulled from the database via sql. The form has, for each record, a textfield for item quantity and subtotal, and a hidden input that holds the item cost price.

Previously, this was calculated by targeting hard coded form field names, however the dynamic nature of this form requires dynamic targeting or a different field naming strategy all together so that the javascript function can iterate through the form fields and calculate subtotals and total on the fly.

Here's the code so far;

The previous calculation function for the single item form:-

function calcForm(){
qty = parseFloat(document.confirmTicketPurchase.ticketQty.value)
if (isNaN(qty)){
alert("You must enter a valid number into the Enter Quantity field")
return false
}
if(qty <=0 || qty % 1 != 0 ){
alert("You must enter a quantity of tickets between 1 and 999 only")
return false
}
costPer = parseFloat(document.confirmTicketPurchase.perticketCost.value)
total = costPer*qty
document.confirmTicketPurchase.ticketCost.value = total
return true
}
I have to edit this javascript function to work with the following form and edit the form field names to suit the function.

The new form :-

<form action="#" name="confirmTicketPurchase" id="confirmTicketPurchase" method="POST">
<table border="0" cellpadding="2" cellspacing="1" class="dataTable">
<tr class="trTopRow">
<td colspan="2">You Have Selected The Following Ticket/s</td>
</tr>
<?php do { ?>
<tr class="trOdd">
<td colspan="2"><strong><?php echo $row_rsTickPurchase['ticketName']; ?></strong></td>
</tr>
<tr class="trEven">
<td width="36%">Enter Quantity:</td>
<td width="64%" class="algn_R"><input name="ticketQty" type="text" id="ticketQty" value="1" size="4" maxlength="4" onkeyup="calcForm()" /></td>
</tr>
<tr class="trEven">
<td>SubTotal:</td>
<td class="algn_R">
<input name="perticketCost" type="hidden" id="perticketCost" value="<?php echo $row_rsTickPurchase['ticketCost1']; ?>" />
<input name="ticketName" type="hidden" id="ticketName" value="<?php echo $row_rsTickPurchase['ticketName']; ?>" />
<input name="ticketID" type="hidden" id="ticketID" value="<?php echo $row_rsTickPurchase['ticketID']; ?>" />
$ <input name="ticketCost" type="text" id="ticketCost" size="12" readonly="true" /></td>
</tr>
<?php } while ($row_rsTickPurchase = mysql_fetch_assoc($rsTickPurchase)); ?>
<tr class="trOdd">
<td>TOTAL:</td>
<td class="algn_R">$
<input name="total" type="text" id="total" size="12" /></td>
</tr>
<tr>
<td colspan="2">Confirm your selection and proceed to Step 6</td>
</tr>
<tr class="trbtn">
<td colspan="2"><input name="userEmail" type="hidden" id="userEmail" value="<?php echo $_SESSION['email']; ?>" />
<input name="step" type="hidden" id="step" value="6" />
<input name="Submit" type="submit" class="loginBtn" value="Confirm" /></td></tr>
</table>
</form>

The calc function is called onLoad and during user input with onkeyup. I'd really appreciate some tips as to how to tackle this one. Currently I'm working on how to get the field names for each form field unique via the php loop which populates the form.

View 2 Replies View Related

Executing An .exe File On Client Side - Run An Pbrush Or Calc

Oct 12, 2011

I am trying to execute an .exe file on client side using javascript, say i want to run an pbrush or calc on client side click using JAVASCRIPT..

I tried this by embedding the following in source page of my web application(ASP.NET)

But i am getting an script error called Automation Server can't create an object

View 3 Replies View Related

Mortgage Calc Adding Extra Decimal Place To Interest Rate

Oct 12, 2009

I have a mortgage calc that is adding an extra decimal place to my interest rate. To see this in action go to: [URL]
Change the interest rate to 7.5
Click Calculate Payment
Click Create Amortization Chart
On the following screen you'll see a recap of your data and the interest rate will now say 7.55. Same thing happens if you enter 6.2. Next screen shows 6.22/. I've attached the html and js files in a zip.

View 2 Replies View Related

Structure And Effeciency On Simple Function ...

Jul 23, 2005

Can this be refined further to be more efficient?

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?

View 7 Replies View Related

Simple Math Function Between Some Textfields

Jun 9, 2009

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?

View 15 Replies View Related

Simple Trim Function Does Not Work

Nov 18, 2010

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
}}

View 4 Replies View Related

Simple Key Event Function Not Working ?

Jul 6, 2009

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.

View 5 Replies View Related

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;
} .....

View 2 Replies View Related

Simple Email Validation Function

Jan 14, 2007

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.

View 3 Replies View Related

JQuery :: Click Function For Simple Slidetoggle

Oct 12, 2010

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.

View 4 Replies View Related

Write A Simple Function That Locates A Parameter In Url?

Jan 21, 2009

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?

View 2 Replies View Related

Simple Echo OnClick Function Not Working

Jul 6, 2010

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.

View 7 Replies View Related

Very Simple Yet Effective Text Zoom Function

Feb 15, 2008

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]
}

}
</script>
<td>
<label for="zoom">Change font size: </label><a href="javascript:do_change_down('text')" id="zoom" name="zoom">-</a>&nbsp;&nbsp;<a href="javascript:do_change_up('text')" name="zoom" id="zoom">+</a>
</td>
</tr>
</table>


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.

View 2 Replies View Related

Simple AppendChild Function Doesn't Work?

Nov 23, 2010

I want to write a function that appends a text string to my div. It seems pretty straight forward and I can't figure out why this doesn't work.

<html>
<head>
<script type="text/javascript">

[code]....

View 6 Replies View Related

Simple Calculation - Error On Function Call

Aug 15, 2011

I have written the following javascript code which makes a simple calculation and writes between the <span> tags using Inner HTML

My code is:
Code:
<html><head>
<script type="text/javascript">
function hesapla() {
kredimiktari = document.hesapla.miktar.value
kredivadesi = document.hesapla.vade.value;
faiz = document.hesapla.faiz.value;
ayliktaksit1 = (kredimiktari * faiz) / kredivadesi;
geriodeme1 = kredimiktari * faiz;
document.getElementById('ayliktaksit').innerHTML = "<strong>Taksit / Ay :</strong>" + ayliktaksit1;
document.getElementById('geriodeme').innerHTML = "<strong>Taksit / Ay :</strong>" + geriodeme1;}
</script></head><body>
<form name="hesapla">

<input type="text" name="miktar" value="Kredi Miktarı" onfocus = "if (this.value == 'Kredi Miktarı') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Miktarı';" />
<input type="text" name="vade" value="Kredi Vadesi" onfocus = "if (this.value == 'Kredi Vadesi') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Vadesi';" />

<input type="text" name="faiz" value="Faiz Oranı" onfocus = "if (this.value == 'Faiz Oranı') this.value = '';" onblur = "if (this.value == '') this.value = 'Faiz Oranı';" />
<div id="gosterim"><span id="ayliktaksit"></span><span id="geriodeme"></span></div>
<input type='button' value='Hesapla' onClick='hesapla()'><br><br>
<img src="images/dot2.png" width="180" height="2" alt="dot"/>
</form></body></html>

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'/>

View 2 Replies View Related

JQuery :: Simple Font Resize Function Not Working In IE

Apr 17, 2011

I have a simple font size function as follows which works fine across safari/firefox but does nothing in IE?[code]...

View 1 Replies View Related

Simple User Defined Function And Text Area

Mar 28, 2011

I am trying to use a user defined function and text area for a project, but nothing is showing up in the text area when i click the button.

View 5 Replies View Related

Simple Animation - SetTimeout Function And Paint Method

Dec 24, 2009

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.

View 1 Replies View Related

Simple Hide - LightBox (Click Function Not Working)

Dec 17, 2010

This code doesn't work.
$('#lightBoxCloseButton').click(function() {
$('.css3Lightbox').hide();
});

View 1 Replies View Related

Write A Simple Function To Animate The Collapse Of A Div Using SetTimeout?

Dec 15, 2010

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!

[Code]...

View 4 Replies View Related

Simple Animation - Loop Function To Display 5 DIVs

Apr 4, 2010

What I want to do is have 5 <div>s displayed in a fixed position on my page. The divs will contain text and pictures. Only one div is displayed at a time, and every 5 seconds, the next div slides over the top of the current div (from right to left) until it is completely obscured. At the conclusion of the fifth, it starts again with number 1.

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved