Simple Javascript calculator of math - nearby!

Hi, I am trying to build a simple mathematical calculator Javascript that will do the following on click of a button:

-Add numbers of textfields imput

-divide the sum by the number of entries

-give the average.

Here is my code. Work (gives rights to answer) but the only problem I have is that the value of the textfield response clears itlsef on the release of the button. But even once, the correct value is briefly indicated in the right textfield.

You can see the page on:

http://www.cazacommunications.com/nonTrad/testCalcl.html

Any clue? Thank you!

- - -

< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > ""

" < html xmlns =" http://www.w3.org/1999/xhtml ">

< head >

< meta http-equiv = "Content-Type" content = text/html"; Charset = UTF-8 "/ >"

< title > Document without name < /title >

< script type = "text/javascript" >

function CalculateSum (Atext, Btext, Ctext, shape)

{

a. var = parseFloat (Atext);

var b. = parseFloat (Btext);

var valueC = parseFloat (Ctext);

Form.REPONSE.Value = (a. + b. + valueC) / 3;

}

/ * ClearForm: this function has 1 argument: form.

It deletes the entry and the answer on the form fields.

He needs to know the names of the elements of the order ENTRY

to do this. */

function ClearForm (form)

{

form.valueA.value = "";

form.valueB.value = "";

form.valueC.value = "";

Form.REPONSE.Value = "";

}

end of JavaScript functions->

< /script >

< / head >

< body >

< do action = "" method = "post" > "

< p > number 1

< input name = "a." type = "text" id = "a" size = "4" maxlength = "4" / >

< /p >

< p > number 2

< input name = "b." type = "text" id = "b" size = "4" maxlength = "4" / >

< /p >

< p > number 3

< input name = "valueC" type = "text" id = "c" size = "4" maxlength = "4" / >

< /p >

< p >

< input type = "submit" name = "btnMoyenne" id = "BtnMoyenne" value = "average" onclick = "CalculateSum (this.form.valueB.value, this.form.valueC.value, this.form.valueA.value, this.form)" / >

< input name = 'response' type = 'text' id = 'response' size = "4" maxlength = "4" / >

< /p >

< p >

< input type = "submit" name = "btnEffacer" id = "btnEffacer" value = "Erase" onclick = "ClearForm (this.form)" / >

< /p >

< / make >

< p > < / p >

< / body >

< / html >

The shape is erased because it is present to himself. Simply add a false back to the "submit call:

Tags: Dreamweaver

Similar Questions

  • Simple Javascript calculation

    Hi - I need help with a calculation simple javascript. I wrote this javascript:

    disadvantages of the var = this.getField ("Text6.0")
    disadvantages of the var = this.getField ("Text5.0")
    If (plan.value! = 0)
    Event.Value = cons.value - plan.value / plan.value
    on the other
    Event.Value = «»

    However, the calculation does not well.  For instance, 105-100 / 100 must be equal to. 05%, however, the script goes out to 0.00%.  Is there a better way to write a script so that the answer comes. 05%?

    Thank you
    Connie

    You need to clarify some things. Your first two lines are if the same variable to the same value. I guess that one of them should be the 'plan' variable, but which?

    Second, you must specify it as the sholw calculation. There are:

    (105 100) / 100 = 5 / 100 = 0.05

    If so, the code would be:

    Event.Value = (cons.value - plan.value) / plan.value;

    But first you need to check to see that plans.value does not evaluate to zero before you run the line of code. This occurs when the plan field is empty, for example. What should be the value of the field when the plan is empty or zero?

  • Simple JavaScript to set the date

    Hello

    My simple JavaScript to fix the date runs in Acrobat Pro, but when I open the same document the reader he sets the date, but it fails with a pop off getField error dialog box... Here's the error tracking script...

    function populate_date()

    {

    var f = this.getField ("ToDay_Date");

    If (! f.value) f.value = util.printd ("d/m/yyyy", new Date());

    }

    populate_date(); call my function

    Above scripts executed when the document is opened. As a Pro, it is stored under Tools/JavaScripts/Document JavaScript...

    When I open it in the drive then I get the following while he dates the date presented too!

    The built-in functions of EScript Acrobat Version 11.0
    Acrobat SOAP 11.0

    TypeError: this.getField is not a function
    2:folder - level: App:Search Script.js

    I have not put right that I get this error...

    Kind regards

    Jeff P.

    I don't understand what you're talking about... The error message made clear reference to a script of level of the folder called 'search Script.js'.

    You must look for the source of the problem here.

  • Help write the Javascript calculation

    OK, here's the problem I'm having. I want to write a javascript calculation to summarize all of the text fields when some choice is selected from a drop-down list field.

    Text fields, I want to do the sum are called: 1 quantity, amount 2... up to 14 amount

    The drop-down list is called: 1 payment, payment 2... all the way to payment 14

    So, I want to write computing sums of tha amount fields correspond with the same number of drop-down list when the drop-down list of selected choice is "refund".

    So if amount 1 is $ 50 and 1 refund payment it adds to the total, but if something else is selected instead it adds just $0.

    Help, please!

    You can use this code as the custom of your total field calculation script:

    var total = 0;

    for (var i = 1; i)<=14; i++)="">

    If (this.getField("Payment"+i).value == 'Refund') {}

    Total += number (this.getField("Amount"+i).value).

    }

    }

    Total = Event.Value;

  • JavaScript calculations "if".

    Hello

    I need assistance with a javascript calculation please. I work on the use of a weight to calculate the field "Ibu", but he would like up to a certain value. For example up to a maximum of 53.3 kg weight, the returned value would be calculated according to the weight multiplied by 0.375. In addition, the value will always be 20. How can I do this? The field reference is called 'Weight' and the calculation is weight * 0.375. I guess I would use one different 'If,' statement, but beyond that I'm totally clueless - have tried Googling, but I'm a bit desperate with java (I could do in a fundamental way back when lol).

    Many thanks in advance,

    Saqib.

    The custom for the field calculation script would be something like the following:

    (function () {
    
        // Get the value of the Weight field
        var v1 = getField("Weight").value;
    
        // Perform the calculation
        var  v2 = 0.375 * v1;
    
        // Set this field value
        event.value = v2 > 20 ? 20 : v2;
    
    })();
    

    This last line is equivalent to:

    if (v2 > 20) {
        event.value = 20;
    } else {
        event.value = v2;
    }
    
  • Updated report with the javascript calculation

    Hi all

    I have an updated report updated when the user fills one column. I then need a simple multiplication based on the user filled in the column and another column to fill in the last column.

    I managed to do it using the JavaScript in the page header
    <script language="JavaScript" type="text/javascript">
    <!--
    function calcit(pThis)
    {
    var vRow = pThis.id.substr(pThis.id.indexOf('_')+1);

    html_GetElement('f03_'+vRow).value = html_GetElement('f02_'+vRow).value * html_GetElement('f01_'+vRow).value;

    }
    //-->
    </script>
    F01 column is a value in a table based on SQL to create the report (AQLSCORE)
    F02 column is what the user fills out (AQLERRORS)
    F03 column is where the calculation is populated (AQLTOTAL)

    With the attribute of the element AQLERRORS = onchange = "additives (this); »

    The problem I have with the above is that it only works when f03 is a text field (that is, the user can change the value) I wish column not editable (the user should not be able to edit this field). If I do the column text display (saves the State) the calculation returns a NaN error.

    When I change the calculation of a * a + the return value 1undefined shows that the value of f01 is indefinite

    Demo app

    http://Apex.Oracle.com/pls/Apex/f?p=15328

    user name: demo
    password: demo

    There are 2 pages that where the calculation works, but with AQLSCORE as a text field, and another where he returned NaN but with AQLSCORE as display text (saved state)

    Any ideas how I can perform the calculation and protect the AQLSCORE of the user column

    Kind regards

    Alex

    Published by: user10942729 on July 30, 2010 08:12

    Take alook at the modifed JS in the header HTML

    The f01_000n elements are display (saves the State) so that they appear as follows in the HTML DOM.

    2
    

    To access the content, you will need to use innerHTML as the 'value' attribute is not in use here.

    BTW, for

    html_GetElement('f03_'+vRow).value 
    

    You can use the shortcut

    $x('f03_'+vRow).value 
    

    Kind regards.

  • JavaScript calculations for quote customers with website html...?

    Hi I'm new to JavaScript, but I know there is a way to do math with her.

    What I'm trying to do is: with html have 2 tags < input > (lets say the ID will be "box1" & "box2")

    the customer visits the site and then type in the 2 boxes of their measurements, IF the 2 measure calculate between 0-1400 square inches the price would display at $512,00 (I needed to generate in an another no editable box/tag, don't know if I would use another entry - unless I did uneditiable somehow - or if it would yield automatically in a kind of beacon of js - as I said (, I'm new to this so please bare with me)

    Then I'll have to add a series of... chains? (I think that what they are qualified...) :

    IF the 2 measure calculate the price between 1401-1700 square inches would calculate at $539.00

    IF 2 measure calculate the price between 1701 and 2000 square inches would calculate $ 566,00

    IF the 2 measure calculate the price between 2001-2300 square inches would calculate $ 592,00

    IF the 2 measure calculate the price between 2301-2600 square inches would calculate to $625.00

    IF the 2 measure calculate the price between 2601-2900 square inches would calculate at $657.00

    and I would need to add about 20 more lines the situation described above... I guess I could just copy and paste each IF statement so I had enough of this code.

    I couldn't link the js with the code on the site I build, or copy it directly in the page Web using the < script > tag, what would you recommend?

    I work on a Mac, with dreamweaver CS6 - this aspect must be compatible for IE in particular and all other browsers.

    Reach:

    http://forums.Adobe.com/index.jspa

    Use the drop down menu to select the Adobe app / service of interest, then click 'Go '.

    Be well...

  • Addition of simple mathematical calculations in forms

    How can I add a calculation to a field?  For example, I have a field called hours.  I would like to have a calculated field called minutes, that's all just hours * 60.  Any thoughts?

    Calculation of the second field in the Simple field Notation tab,.

    Enter this:

    Field1 * 60

    (field1 replace with the name of the first field, of course. In addition, this name

    It should not contain any spaces or points)

  • Problem with users simple Javascript running in an Active Directory environment

    I support the local government environment.
    After the latest updates for firefox 25.0.1 and Java 7 update 45 we are facing a lot of difficulties to access the sites provided by the central Government.
    In some cases, the problems are solved by re - install java or that allow plugins to run.
    In a particular case, we can access all the features (same photos and links to java scripts) to a site by using an administrator account, but cannot use a simple user. Activation of java deployment toolkit and Java (TM) platform plugins for the site did not work.
    Computers face the problem to run Windows XP Pro + SP3.

    The same issue does not appear when you run google chrome...

    Hello ageorgopoulos,

    Please contact the Mozilla Support. This seems to be a difficult issue and I hope that we can help you.

    • Did you try a hard refresh of the page with Ctrl + F5?
    • Also have you tried to see if there are errors listed in the Web console Tools > developers Web > Web Console?

    See you soon,.
    Patrick

  • Simple Javascript question

    Please forgive me, I am very new to JavaScript and Acrobat.

    Can someone tell me the phrase I would use to several a number entered by a user; which would be multiplied by a fixed number? Please see image:

    The user number of backpacks, they enter the first area, the second box would have several sales of 50.

    Please let me know if you have any question. I spent some time trying to get this to work, everything I try the product and error.

    Your help is very appreciated!

    Hi rachelNS,

    You can send me a sample form and I would try it for you.

    Then you check the script on your side. Also, I would like to know what is the version of Acrobat you are using?

    Kind regards

    Ajlan Huda.

  • Simple javascript for the drop-down list IF, fills two different fields

    I don't write js, but can grasp what it did when I hang a sample edit and re - purpose. I have a form simple fax that already resets to the opening. Here's what I'm doing:

    User selects the sender's name in the drop-down list of about 15 (grow w / hour)

    Fill in the following text field "sender Fax #" with the number of direct fax (xxx-xxx-xxxx in the js) user

    Are also complete this later text field "sender Ph #" with the number of direct ph of the user (xxx-xxx-xxxx in the js)

    Here is an example which I believe works the way you want: https://workspaces.acrobat.com/?d=gZNDS8dQQNqvwocUufXHNQ

    You have to watch the fields to see how they are implemented and to study different scripts to see how it works. If you have any questions, post again.

  • How to save a copy of the file? (simple javascript needed)

    I'm a noob, so need a Javascript/installation for InDesign CC script, which runs automatically when a file is openand saves a copy of the document to a specific folder, to the present time (i.e. "c:/file/filename_COPY_6_MAY_2014_23_59_59").

    This code is just for this work? :

    var dmd = app.activeDocument;
    var oldDocName = dmd.name;
    //make new file
    var newDocName = oldDocName.substring(0,oldDocName.length-5); //removes ".indd"
    var dd = new Date;
    var NewFile = new File("/c/backups_folder/" + newDocName + dd.getDate() + "_" + dd.getMonth() +  "_" + dd.getHours() + "-" + dd.getMinutes() + "-" + dd.getSeconds() +".indd");
    //copy
    oldDocName.copy(NewFile);
    
    
    
    
    
    
    
    
    
    

    Hi all

    I don't think that the link you have provided on stackflow meets your problem and certainly not the best way.

    Hopkins response for sure does not seem be correct (sorry)

    I think that my script below is the best method.  Don't lead to annoying delays in file open.

    Put it in your startup script file

    Trevor

    // https://forums.adobe.com/message/6363852#6363852
    // By Trevor
    #targetengine document_copy
    (function () {
        if (app.eventListeners.itemByName ("saveCopy").isValid) app.eventListeners.itemByName ("saveCopy").remove(); // makes debugging easier and prevents multiple eventListener creations
        var mySaveCopyEventListener = app.eventListeners.add("afterOpen", saveCopy);
        mySaveCopyEventListener.name = "saveCopy";
    }) ();
    
    function saveCopy(ev)  {
        if (ev.target.constructor.name !== 'Document') return;
        saveCopy.Folder = "C:/backups_folder/"; // Change as needed
        if (!Folder (saveCopy.Folder).exists) {
            Folder (saveCopy.Folder).create();
            $.sleep(300);
        }
        if (!ev.fullName.copy (new File (
            saveCopy.Folder + // folder name
            ev.fullName.name.replace(/.[^.]*$/,"") + // file name without suffix
            (" " + new Date).replace (/:/g,"\xB7").replace(/\s\S+$/,"") + // date Change format as desired
            (ev.fullName.name.match(/\..+$/) ? ev.fullName.name.match(/\..+$/).toString() : ".indd") // suffix could be idml or who know what
            ))) alert ("Something messed up, a copy was not made");
    }  
    
  • Calculation of math Cap reset?

    Hi guys

    How do you cap a math calc so that if it is capped at zero the result is going to be negative? Is there a func?

    See you soon

    :

    yourcalculatedvalue = Math.max(0,yourcalculatedvalue)

  • Division of JavaScript calculations

    I have sucessfully added values of the 6 groups of radio button in my form (using the script below) and I now want to divide by 6 to get the average before the result is displayed in the field. Can someone tell me what to add the script to do this? I'm a novice at Javascript and depend on this forum to help me who I want to say thank you for. This forum has seen me through a lot of project tasks asked of me.

    parseInt (Strategic.Strategic1.rawValue)

    + parseInt (BusKnowledge.Knowledge.rawValue)

     

    + parseInt (Compliance.Compliance1.rawValue)

    + parseInt (Decision.Decision1.rawValue)

    + parseInt (Demeanor.Demeanor1.rawValue)

     

    + parseInt (Relationships.Relationships1.rawValue);

    Hello

    FormCalc is delivered with an average function that you can use.

    Just put this script to calculate the field event to display averages:

    Avg(Strategic.Strategic1.rawValue, BusKnowledge.Knowledge.rawValue, Compliance.Compliance1.rawValue, Decision.Decision1.rawValue, Demeanor.Demeanor1.rawValue, Relationships.Relationships1.rawValue)
    
  • Simple sum calculation does not

    This calculation of amount doesn't seem to work, any idea why?

    There is a picture of my form.

    http://DL.dropbox.com/u/11608065/sum1.PNG

    I added $1, the left column works and the bottom is not.

    http://DL.dropbox.com/u/11608065/Sum2.PNG

    I added $1, the right column works and the bottom is not.

    http://DL.dropbox.com/u/11608065/Sum3.PNG

    Here I have added $1 to the column on the right first.

    http://DL.dropbox.com/u/11608065/Sum4.PNG

    And then the left. Same result. Thoughts?

    http://DL.dropbox.com/u/11608065/Sum5.PNG

    The order of computation of field is probably wrong. To define it, go into the mode of creation of form (forms > add or edit fields) and select: forms > edit fields > set field calculation order

    and set it to anything that makes sense for your form.

Maybe you are looking for

  • HP service plugin - A5-sized paper

    Based on the advice of erico, I can connect my officejet hp 6700 to my nexus 7. However, when I try to print a word with an A5 page layout document, it only print on 50% of a page A5. I tried all size available on the plugin page (4 x 6 inches, 5x7in

  • Extract data from graph XY

    Hello Here, I want to extract data from the XY graph. I joined vi which I use for table 1 d. How can I use this for 2D table VI. Thank you

  • Photosmart 5510-e-all-in-0ne B: ink is not placed on a paper

    Printer acts like it is printing but is not put on paper ink. Printer recognizes the new HP 564 black ink cartridge is installed. Tried an another new ink cartridge. Printer worked correctly in the past. She continued print correctly printed a few li

  • Recovery Windows exp CD

    Your search: I the paresario of Compaq 40100 $M... I created my recovery of my computer disks during the creation of the CD #3 there were many error on copying files, I kept pressing retry or ignore the entire process. complete preocess. I cam to rei

  • export images to a memory card

    I want to put photos on my memeory for my digital camera card. does anyone know how to do?