0

my HTML look like this

<table>
    <tr>
        <td>Input 1</td>
        <td>Input 2</td>
        <td>Total</td>
        <td>&nbsp;</td>
        </tr>
            <tr>
        <td><input></td>
        <td><input></td>
        <td><input disabled></td>
        <td><button value="add">Add</button></td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>Grand Total</td>
        <td><input disabled ></td>
        <td>&nbsp;</td>
        </tr>
    </table>

i`m trying to calculate between two input and can add new row after that using javascrtpt... pls help me..

4
  • 4
    Which part do you have a problem with? Please show your existing code. Commented May 23, 2012 at 7:26
  • your question is not clear ! more info please Commented May 23, 2012 at 7:31
  • i dont have existing code.. the problem is im not good in javascript... i just want to calculate between two input, at the same time, i`m able to add new row, and make another calculation... thanks Commented May 23, 2012 at 7:32
  • as u can see from html above, ive got two input... for example input 1 = 10 input 2 = 2 total = sum of input 1 + input 2 if i press add button, im able to add new row and make another calculation.. thanks Commented May 23, 2012 at 7:34

1 Answer 1

1

you can do it in two ways give id to your table, access your table object then add a new row by table.innerhtnl+= your new rows tags. or also in this way

function addRow(tableID) {
        inp1 = document.getElementByID(input1).value;
        inp2 = document.getElementByID(input2).value;
        if(your Logic to check inputs)
        {
        var table = document.getElementById(tableID);

        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);

        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "checkbox";
        cell1.appendChild(element1);

        var cell2 = row.insertCell(1);
        cell2.innerHTML = rowCount + 1;

        var cell3 = row.insertCell(2);
        var element2 = document.createElement("input");
        element2.type = "text";
        cell3.appendChild(element2);
        }
    }

for demo visit here

Sign up to request clarification or add additional context in comments.

5 Comments

wht you really want plz explain its nt clear. the above code can help you to create a row dynamically in a table. whats your other requirement????
yes... the above code can create a row dynamically.. thank you... the problem is, at the same time, i want to make a calculation between 2 INPUT...
yeah modify the function, get the values in the above function of the two inputs, thn compare thm create some if logic then you can get the code workin exactly the way you want. !! do u want help on the logic too???
:) i hope u give me the fully working code... i appreciate your help.. thanks for understand my question... it seem like very easy to you..
check it nw you appear to be newbie to javascript. understand first the js , go through some tutorials then you will be able to do code in js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.