how to perform computation in the table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • malika
    New Member
    • Apr 2013
    • 7

    #1

    how to perform computation in the table

    hi everyone my question is that i get the number of tables which according to the user input in the texbox but when i perform computation in first table mean addittion of first three column give me result in fourth column but in second table i dont get the result.i have used the javascripting plz help me if anyone knoes the answer

    javascripting
    Code:
     function getText3(){
          var in1=document.getElementById('in1').value;
          var in2=document.getElementById('in2').value;
    	    var in4=document.getElementById('in4').value;
          var in3=(in1*in2*in4*30)/1000;
          document.getElementById('in3').value=in3.toFixed(2);
    
       }
     function getText4(){
          var in11=document.getElementById('in11').value;
          var in22=document.getElementById('in22').value;
    	    var in44=document.getElementById('in44').value;
          var in33=(in11*in22*in44*30)/1000;
          document.getElementById('in33').value=in33.toFixed(2);
       }
    table coding
    Code:
    <body>
      
            <table border="1" align="center" id="wr123">
    		<?php $numberofrow = $de;?>
    		<?php for($counter = 1;$counter<=$numberofrow;$counter++){ ?>
                <tr>
                    <th>AS</th>
                    <th>WAS</th>
                    <th>NO.</th>
                    <th>AVERAGE</th>
                    <th>APPROX</th>
                    <th>APPROX.</th>
                    <th>Cons</th>
                </tr>
                <tr>
                    <td>Tube</td>
                    <td>
                        <select id="in4" name="t1" onclick="getText3()" onchange="getText39()" onchange="getText89()">
                            <option value="0">0</option>
                            <option value="12">12</option>
                            <option value="18">18</option>
                            <option value="24">24</option>
                            <option value="75">75</option>
                        </select>
                    </td>
                    <td>
                        <input type="text" name="t2" id="in1" onclick="getText3()" onchange="getText39()" onmouseout="getText89()" />
                    </td>
                    <td>
                        <select name="a1" id="in2" onclick="getText3()" onchange="getText39()">
                            <option value="0">0</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                        </select>
                    </td>
                    <td>
                        <input type="text" id="in3" name="username" readonly="readonly" />
                    </td>
                    <td>
    <tr>
                    <td>FAN</td>
                    <td>
                        <input type="text" name="t11" id="in44" value="100" />
                    </td>
                    <td>
                        <input type="text" name="t22" id="in11" onclick="getText4()" onchange="getText37()" onmouseout="getText98()" />
                    </td>
                    <td>
                        <select name="a11" id="in22" onclick="getText4()" onchange="getText37()">
                            <option value="0">0</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                        </select>
                    </td>
                    <td>
                        <input type="text" id="in33" name="name" readonly="readonly" />
                    </td>
                    <td>
      </tr>
    			<?php }?>
    Last edited by acoder; May 27 '13, 12:20 PM. Reason: Separated code
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    malika,

    First off, this question should probably be asked in the JavaScript forum. But that's not critical.

    I notice that the functions you call like getText39() and getText89() are not defined. Could that be part of your problem?

    Also, in HTML, you are not allowed to have more than one tag with the same id. If your table has multiple rows repeating the same inputs, you will have the same id repeated multiple times. This guarantees that your JavaScript will be malbehaved.

    Comment

    • malika
      New Member
      • Apr 2013
      • 7

      #3
      can u plz code how can i do ths as i am new in php n javascripting not much know of it

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        malika,

        In a word no. You have to do your own work, so you can understand how to finish your own problems.

        What you can do is use PHP and JavaScript creatively to resolve your problem - a hint - have you considered using PHP to create labels for the inputs?

        Oralloy

        Comment

        Working...