Create the calculated in PHP form field

Hello

I am trying to create a calculated field that will take care of the average of the ratings when a form is entered. This field will then submit the average value and the shape at the end (that's why I need the value to calculate before sending the form - that is, as the form is filled out).

I found the following code (designed for HTML forms rather than PHP forms, but I hope that it might work). It doesn't seem to do anything - the field displays no information. Help?

< script language = javascript >

< !--/ /

function dm (amount)

{

String = ' ' + amount;

DEC = string.length - string.indexOf('.');

If (string.indexOf('.') == - 1).

Returns the string + '. 00';

If (dec == 1)

return string + ' 00 ";

If (dec == 2)

return string + '0';

If (dec 3)

return string.substring(0,string.length-dec+3);

Returns the string;

}

function calculate)

{

Opp1 = 0;  Inv1 = 0;  COM1 = 0;  wlb1 = 0;  COM2 = 0;  Atm1 = 0;  PAR1 = 0;  Increase 1 = 0;  Rew1 = 0;  Env1 = 0;  Gro1 = 0;

If (document.form1.Opportunity.value > "")

{Opp1 = document.form1.Opportunity.value};

document. Form1.opportunity.value = eval (Opp1);

If (document.form1.Investment.value > "")

{Inv1 = document.form1.Investment.value};

document. Form1.investment.value = eval (Inv1);

If (document.form1.Community.value > "")

{Com1 = document.form1.Community.value};

document.Form1.Community.Value = eval (Com1);

If (document.form1.WLB.value > "")

{wlb1 = document.form1.WLB.value};

document. Form1.WLB.value = eval (wlb1);

If (document.form1.Communication.value > "")

{Com2 = document.form1.Communication.value};

document.Form1.communication.Value = eval (Com2);

If (document.form1.Atmosphere.value > "")

{Atm1 = document.form1.Atmosphere.value};

document. Form1.atmosphere.value = eval (Atm1);

If (document.form1.Performance.value > "")

{PAR1 = document.form1.Performance.value};

document. Form1.performance.value = eval (Per1);

If (document.form1.Inclusion.value > "")

{Increase 1 = document.form1.Inclusion.value};

document. Form1.inclusion.value = eval (Inc1);

If (document.form1.Rewards.value > "")

{Rew1 = document.form1.Rewards.value};

document. Form1.rewards.value = eval (Rew1);

If (document.form1.Environment.value > "")

{Env1 = document.form1.Environment.value};

document. Form1.environment.value = eval (Env1);

If (document.form1.Groups.value > "")

{Gro1 = document.form1.Groups.value};

document. Form1.groups.value = eval (Gro1);

Totamt =

eval (Opp1) +.

eval (Inv1) +.

eval (COM1) +.

eval (wlb1) +.

eval (COM2).

eval (Atm1) +.

eval (Per1) +.

eval (Inc1) +.

eval (Rew1) +.

eval (Env1) +.

eval (Gro1);

document. Form1.GrandTotal.value = dm (eval (Totamt));

}

->

< /script >

Any suggestions gratefully received.

Sorry for the explanation of the solution, this is why you shouldn't let dyslexia on the forums...

Yes, you can put onChange = "calculate ()" within any html element, but it will only work for items that have a 'value' that can change, such as "

The average value can be reported by adding any of the following lines:

Happy scripting!

Tags: Dreamweaver

Similar Questions

  • Treatment options for form (use the value of a form field to select a shared list or a web redirect page)

    Hello

    I tried something with the processing of the forms which doesn't seem to work. I wonder if the function really works or if I'm doing something wrong.

    Here is an example of what I do: I have a form that I want to use. I add "Web Page redirection" processing step to my form. When I click on the processing step to set up, under "General settings" there is an option that says "Choose how the launch of destination page is selected." In this drop-down menu, there are three options: always redirect to the same landing page, use a drop-down list to select the landing page and the value of a form field allows you to select the destination page. I have a hidden field on the form that contains the URL of the web page to which I would like to redirect. When I select 'Use the value of a form field to select the landing page', I select the hidden field to the field that contains the URL of the web page to which I want to redirect. It's my setup. However, when I submit the form, nothing happens, I do not redirect to the URL contained in the hidden field... This function still works? I'm doing something wrong? I can't seem to get the function "Use a drop-down list to select the destination page" to work either. The same thing happens when I try to use the "Add Contact to shared the list" processing step. I add the name of the list that is shared in the field hidden, but the contact does not appear in the shared list... These functions still work? If yes how do I configure them?

    Thank you!

    Well, I understood the problem of the shared list... You must add the ID of the list shared in the hidden field. I had to use Firebug to see the real ID of the shared list. Once you have the ID, use you it as a static value in the field. If the HTML code of the form will look something like this:

    If you do not use the lookup data ID. You use the ID real asset on the shared list. You must use something like Firebug to find.

    I'm glad everything is working.

  • Can I copy the contents of a form field to another field with toggle checkbox?

    Would it not possible to copy the contents of a form field to another field in the form once a checkbox is disabled?

    I have several form fields that require form-fill to enter their initials.  Rather than repeat this 20 - 30 times on a form, they would like to be able to write their initials somewhere and that their initials copy in another form with a checkbox Toggle field.

    So, I have a field called 'initial' and each of the original boxes are "init_entry1" "init_entry2" etc.

    The boxes for these areas are "check_entry1" "check_entry2" etc.

    This would be possible with scripts?  Or are there better ways to accomplish the initial AutoComplete with a checkbox toggle?

    You can use a code like this in the MouseUp event of your box:

    If (getField("Check_Box1").value! = "Off")

    getField("Text2").value = getField("Text1").value;

    else getField("Text2").value = "";

    Of course, you have to adapt the names of the fields.

  • Auto create the value of a given field based on the range of percentage in another area

    Hello, people forum!  I am trying to create a field that fills a score based on the percentage in another area.  To this end, I have a field that autocalculates a percentage based on two other fields.  I would be close to a third field which, for example, the rate less 75% 2... 75 - 85% 3... and more than 85% 4.  I can't understand the syntax to make it happen, can anyone of you help?

    For the edification, my percentage field looks like:

    Calculation of the percentage of rock - use the number Format "percentage".

    If (this.getField("RockTotalQ").value == 0) {}
    Event.Value = 0;
    } else {}
    Event.Value = this.getField("RockComplQ").value/this.getField ("RockTotalQ") .value;
    }

    Thank you.

    You can use something like this than the calculation script custom in the other field (make sure that it appears after the 'Percentage of Rock' field in the calculation order, if!):

    var v = this.getField("Rock Percentage").valueAsString;
    if (v=="") event.value = "";
    else {
        v = Number(v);
        if (v<=0.75) event.value = 2;
        else if (v<=0.85) event.value = 3;
        else event.value = 4;
    }
    
  • Acrobat XI - preventing the creation of automatic form field

    How can I stop Acrobat XI automatically creating form fields interactive when I convert a document existing (pdf) form.  I know that I can delete them manually, but I convert custom documents several times a day and I want to eliminate extra steps to remove fields that I don't need.

    You should be able to open the PDF file, select ' tools > forms > edit ' and when you are prompted to have Acrobat automatically detects form fields, answer No you will then be in the form of editing mode where you can add them manually.

  • Change the name of the custom in a form fields

    I created a custom form for a client, however, when I test the e-mail received just watch "custom field" next to the entrance instead of address, phone, ect... How do I change this?

    Select the form field in Muse, and then click the blue "play button" at the top right of this one.

    Check the "Label".

    Edit the label to your liking.

    Go back and uncheck the option label to hide on the web page.

    Republish and tada!

  • Export the contents of a form field from InDesign to PDF format

    I create form fields in InDesign that will be exported to interactive PDF.  When I create the PDF file the form fields are exported, but not all of the content in the text fields.  I have to add it manually in Acrobat.  Is it possible to keep this content when exporting?

    FormMagic does this and much more:

    http://www.ID-extras.com/products/formmagic

  • using the value of a form field in another form field

    I hope that I can describe my problem. Please bear with me

    I have a worksheet with a lot of form fields. For most of the text boxes and a few drop-down list boxes.

    I use a lot of custom calculation scripts to determine what information auto fills in most of the fields.

    But I have problems with a last form named ORTHOPLANID field.

    The value that it auto fills depends on two other fields. A field is called MEDOOP. The other field is SUPPDENPLANID. I tried to use an if/then/else statement for ORTHOPLANID but it does not work. I'm guessing it doesn't b/c, the value of the MEDOOP field is generated from an if / then statement so I don't know whether or not the script recognizes its value as a real value.

    Is there another way to get around this? I don't know if I have clearly explained the problem, but I hope someone can help

    Thank you

    Brandy

    I think I know what the problem... You did not drop-down fields

    commit their selected values immediately (under Properties - Options). As one

    result, the calculations take place when you exit the field (i.e. click)

    outside), and not when you do a

    selection.

  • Get the name of the file attachment php form

    This should be simple enough, right? Gets the name of the file attached a form submission so I can insert it into a database.

    < input type = "file" name = "attached_file" class = "attached_file" >

    $attached_file = $_POST ['attached_file'];

    echo $attached_file;

    Pings above back squat diddly.

    See you soon

    Operating system

    In the files Panel, it should be tmp_name:

    $_FILES ['upload'] ['tmp_name'] / / where the download is the name of the field

  • Problem with the calculation script - dividing one field (a number) but another field (a number that corresponds to a sum of other fields)

    I have a table that contains the users to enter the number of books in a type of food (Fruits & vegetables, products dairy, protein, grains, etc.). There are 8 fields whose amounts are totaled in a field (PoundsTOTAL) using the calculation of "value is the sum...". ».

    The question that I am running is that for each type of food, there is also a percentage field that indicates the percentage of the total books that represents the type of food. If I used the simplified field notation (PoundsDairy / PoundsTotal * 100) I get the dreaded "the value entered does not match the format of the field" because the PoundsTOTAL field is 0 until someone between numbers in the fields above him. I tried using the code I found on this forum, but it does not work for me (I do not know I did something wrong). I enter a number like 500 in the field of the PoundsFV and the PercentFV field shows nothing.

    Here is the code I use for one of these calculations:

    (function () {}

    Get the field values as numbers

    var lbsfv = + getField("PoundsFV").value;

    var lbsttl = + getField("PoundsTotal").value;

    Perform the calculation and the value of this field will cause

    If (lbsttl! == 0) {}

    Event.Value = lbsfv / lbsttl;

    } else {}

    If lbsttl = 0, this field blank

    Event.Value = "";

    }

    })();

    For reference, the referenced fields are shown in this image:

    .FormCalcs.jpg

    Your domain is named PoundsTOTAL, not PoundsTotal.

  • Allows to manage the events of JSP form fields

    The use of JavaScript is a way to manage the attributes of event like onClick form fields...
    What is the best way to handle this in JSP? For example, I have a form with a textarea field and wish to receive a notification every time the user enters something inside the text box.
    Thank you
    Roni

    The only way to handle this event is to use javascript. What to do exactly? JavaScript seems to be enough to pair with such things. You can also use AJAX if you need to do sth on a server side.

  • Order creating the calculated in the PivotTable item

    Hello evereybody!

    I have a question about pivot table.

    When I created a new calculated item in the pages on PivotTable section always appear down the list. Can I have any order?

    Example: I put in the section of the page: Dim departments and I have 25 departments. I create something calculated to get the sum of all (like all the choices on command prompt), but this element appears in the last position. I would like to see in the front row. Is possible?

    Thank you!!!

    Hello

    Instead of using a new element calculated , using Total (click the sigma Pages option) > front

    Now, it shows that as first values in the drop-down list.

    Thank you & best regards
    Kishore Guggilla

  • Buliding a SELECT in the PSP using html form fields

    Hi everyone, first of all to forgive me my poor English.

    I do "Basis of CV" in PSP as a school project. And I have a search like this (simple version) html form:

    Select list: Profession
    text field: age

    And my question is... How to build a select in psp that will analyze only the given parameters? For example. I'm looking for C programmer in any age, so I Selects C Pogrammer in the list and let afe field blank. The SELECTION should be sth like this: select * the person where the Profession as "C Programmer" But in another search, I need a programmer who has 25 years... Select has one OR more... I'm sure you all know what I mean

    Please help me.
    Martin

    Hello

    According to the information you provided it seems that you may need to use dynamic SQL statements, lok at the following link for more information.

    http://download.Oracle.com/docs/CD/B10500_01/AppDev.920/a96590/adg09dyn.htm

    It is preferable to use Bind varaibale will improve query performance you and avoid the query SQL injection attack.

    Thank you

  • create the user in a form

    I want to create a user in a trigger of form such as Pre_insert or other trigger

    CREATE a USER: daten.oracle_user PROFILE "DEFAULT" IDENTIFIED BY "xy".
    DEFAULT PASSWORD EXPIRATION
    TABLESPACE TEMPORARY "USERS."
    TABLESPACE 'TEMP' ACCOUNT UNLOCK;
    GRANT 'CONNECT' to: daten.oracle_user;
    GRANT "DBA" to: daten.oracle_user;

    does not work when I compile. How can I solve the problem to create a user in a form?

    highly recommended German responses.

    I use

    ORACLE FORMS DEVELOPER AND SERVER FORMS 6i (Patch 2) RELEASE NOTES

    and I think its a version of database 8. but I am not shure

    Hello!
    Do not do that the DDL statements in a before insert trigger
    cause you are submitting a commit in the middle of a transaction of forms!

    Use a key trigger or button as a trigger:

    forms_ddl ( 'CREATE USER ' || :daten.oracle_user || ' PROFILE "DEFAULT" IDENTIFIED BY "xy"' ||
                ' PASSWORD EXPIRE DEFAULT' ||
                ' TABLESPACE "USERS" TEMPORARY' ||
                ' TABLESPACE "TEMP" ACCOUNT UNLOCK' );
    forms_ddl ( 'GRANT "CONNECT" TO ' || :daten.oracle_user );
    forms_ddl ( 'GRANT "DBA" TO ' || :daten.oracle_user );
    

    Concerning

  • PHP form field not displayed [was: Beginner problem.]

    Hello good people.

    I have a very simple question.

    Here's my index.html

    < ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "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 = UTF-8 "/ >"
    < title > Test PHP < /title >
    < style >
    {body
    margin: 50px; background-color: #232323; do-family: without serif. color: #B7B7B7; font-size: 13px;
    }
    Input, textarea {}
    border: 1px solid #464646; background-color: #1C1C1C; do-family: without serif. color: #CECECE; do-size: 10px; margin-top: 15px; margin-bottom: 15px;
    }
    {#submit}
    font-size: 13px;
    }
    < / style >
    < / head >

    < body >
    < do action = "index.php" method = "post" > "
    What's your name? < br / >
    < input type = "text" name = "name" / > < br / >
    What is your age? < br / >
    < input type = "text" name = "age" / > < br / >
    < textarea type = "text" name = "tekstas" rows = "5" cols = "40" > your message. < / textarea > < br / > < br / >
    < input type = "submit" value = "Go!" id = "submit" / >
    < / make >
    < / body >
    < / html >

    And index.php

    <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > ""
    " < html xmlns =" http://www.w3.org/1999/xhtml ">
    < head >
    < style >
    {body
    margin: 50px; background-color: #232323; do-family: without serif. color: #B7B7B7; font-size: 13px;
    }
    < / style >
    < meta http-equiv = "Content-Type" content = text/html"; Charset = UTF-8 "/ >"
    < title > PHP < /title > result
    < / head >

    < body >
    <? PHP
    SetType ($_POST ["age"], "integer");
    echo 'your name is. " $_POST ['name']. "< br / > ';
    If ($_POST ["age"]! = 0) echo "your age is." $_POST ['age']. "< br / > < br / > ';
    "If ($_POST ["age"] = 0) echo"Please indicate your age."." < br / > < br / > ';

    echo "< b > Message: < /b > < br / >". "." $_POST ['tekstas"];
    ? >
    < / body >
    < / html >

    The question is:

    Why the part of the age of php does not work properly? If I leave it black or type zero in the age < input >, PHP simply ignores the part 'Please specify your age' code.

    You're relatively new to this forum. Welcome.

    Please take a moment to read How to get help quickly. Using a subject like "Newbie problem" line makes no sense and is likely to be ignored at busy periods. Always try to use a descriptive subject line.

    The answer to your problem is very simple. This is the error of the beginner town that attracts even more experienced people from time to time. It is in this line:

    if ($_POST["age"]=0 ) echo "Please specify your age."."

    ";

    You used only one sign "equal", which assigns the value to a variable, then it always equals TRUE.

    To compare two values, you must use two equal signs like this:

    if ($_POST["age"] == 0 ) echo "Please specify your age."."

    ";

    There are other things that could be done to improve your code, but which solves the underlying problem.

Maybe you are looking for