Undetected mistake

Before anything I would like to say that I am beginner and working on a project, so bare with me and show some understanding.

So what I am trying to achieve is to call 3 different columns from my database, which is a local MySQL database, and then, with the help of a custom equation, I would like to show my outcome. And up-until now I have created the database, coded the php and the Javascript. Now I beleive that I have some issues with the Javascript part, hence the thread.Now if you look below you will find the outcome that I am trying to achieve, unfortunately the outcome is from an excel file, and that is why I am posting my code as well as an image of that calculator.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title> AAA </title>
  <script>document.write ("AAA <br/>") </script>
  <!---------------------First try to create the Javascript---------------------->
      <script type="text/javascript">

        callfunction() {
        var val = document.getElementById('Title').field_paint_efficeincy__value();

        pos= val*area
        }
          areafunction() {

           perimeter = document.getElementById("PE");
           height =  document.getElementById("He");
           doors =  document.getElementById("Nd");
           closets = document.getElementById("Nc");
           windows =  document.getElementById("Nw");
          // You get the selected value in val variable. Here you can calculate what you want
           area = (perimeter*height)-windows-closets-doors
           document.getElementById("result").innerHTML = (perimeter*height)-windows-closets-doors;
          }
         timesfuction() {
            var val2 = document.getElementById('Title').field_paint_times_value();
            document.getElementById("result").innerHTML =val2;
          }
          document.write("AREA: ",area);
          document.write("TIMES: ", val2);
          document.write("POS: ", pos);

      </script>
  <!----------------------------------------------------------------------------->
</head>
<body>
    <?php

    $host = '';


    @$user = '';


    @$pass = '';

    $db_name= '';
    $conn = new mysqli($host, $user, $pass, $db_name);
//----------------------------User defiend values------------------------------
    @$p = $_POST['P'];
    @$h = $_POST['H'];
    @$d = $_POST['D'];
    @$w = $_POST['W'];
    @$c = $_POST['C'];
    @$K1 = $_POST['kal'];
    @$K2 = $_POST['KaL'];
    @$K3 = $_POST['KAL'];
    @$b = $_POST['bal'];
    @$pw = $_POST['P_W'];
    @$pr = $_POST['P_R'];
//------------------------------------------------------------------------------

//---------------------------------DB Query-------------------------------------
    $query = mysqli_query($conn,"SELECT n.title, e.field_paint_efficeincy__value, t.field_paint_times_value FROM node_revision as n, field_data_field_paint_times as t, field_data_field_paint_efficeincy_  as e WHERE n.nid=t.entity_id OR n.vid=e.revision_id");
//------------------------------------------------------------------------------

//-----------------------Echoing the Javascript equation------------------------
    echo '<select name="title"  id="Title" onchange="callfunction()">';
//------------------------------------------------------------------------------
//


//if(isset($_GET["P"])) {
//   $keyword= $conn->escape_string($_GET["P"]);
//   $conn = new mysqli($host, $user, $pass, $db_name);
//   $resault = $conn->query("SELECT * FROM node_revision INNER JOIN field_data_field_paint_efficeincy_ ON  nid=entity_id WHERE title LIKE '$keyword%' ");
// echo $resault->num_rows;


//if ($resault->num_rows) {
//     while($row = $resault->fetch_assoc()) {
//           echo $row['field_paint_efficeincy__value'], ' ', $row['entity_id'] . "<br />";
//     }
//  }
//$conn->close();
//}

//τεστ

//-While loop that checks for the titles and then put those on a dropdown menu--
    while ($row = mysqli_fetch_array($query)){
      echo '<option value="' . $row['title'] . '" ">' . $row['title'] . '</option>';
      };
    echo "</select>";

    while ($row = mysqli_fetch_array($query)){
      $row2 = mysqli_fetch_assoc($row);
      echo "text: "; echo $row2;
    };

//------------------------------------------------------------------------------






//-------------------------Fetching data from MySQL-----------------------------
;

    while ($rows2 = mysqli_fetch_array($query)) {
        echo '<var name="field_paint_efficeincy__value" id="select_paint_eff_value" onchange="callfunction(eff);>';
        $ef=$rows2['field_paint_efficeincy__value'];
        echo "</var>";

};
//------------------------------------------------------------------------------
?>



<!-----------Boxes for the user defiene some values that we will need---------->
    <br/>
    <form action="<?php //echo $_SERVER['PHP_SELF']?>" method="get">
<!--    <form action="" method="post"> -->
        PERIMETER: <input type="number" id="Pe" name="P" value="0" /> <br/>
        HEIGHT: <input type="number" id="He" name="H" value="0" /> <br />
        DOORS: <input type="number" id="Nd" name="D" value="0"  /><br />
        WINDOWS: <input type="number" id="Nw" name="W" value="0"  /><br />
        CLOSETS: <input type="number" id="Nc" name="C" value="0" /><br />
        <input type="button" onClick="areafuction()" Value="AREA (m²)" /><br />
        <input type="button" onClick="timesfuction()" Value="times" /><br />
        <input type="button" onClick="callfuction()" Value="CACLCULATION" /><br />
        <input type="submit" value="CALC" name="sub">
    </form>

<span id = "result"></span>
</body>
</html>

As you can understand my table has 3 columns; the title of a product, the times that this product needs and the efficiency of that product.Using these 3 columns and some user inputs I want to calculate the area, the custom equation which calculates the efficiency*the times of the product that needs to be applied and after those calculations I want to print them as well as number of the times.If I wasn’t clear I apologize because English isn’t my native tongue, and yes I know about AJAX and jquery but again I am new and I am trying to create something simple.

In area_function(), all of your getElementByID calls need to be looking a the value of the element, not the element itself.

i.e.

perimeter = document.getElementById("PE").value;
1 Like

Is that all or do I need to rewrite something else?

You need to do that will ALL the getElementById calls in areaFunction(). After that, you’ll need to test to see if it works, or not.

document.write() is effectively obsolete as it has significant problems unless you are an expert at JavaScript and know exactly how to use it properly. Most things it used to be needed for with Netscape 4 can now be done in dozens of better ways.

Almost all JavaScript is best placed immediately before the </body> tag. There are only a couple of fairly specific purpose scripts that need to go in the head (because they need to run before the page starts rendering).

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.