this is my html and javascript coding. how to do contenteditable div onkeyup calculation. i tried it but i doesn't work...

        <td><div class="inputclass" id="quantity1" contenteditable> </div></td>
        <td><div class="inputclass" id="unitprice1" onkeyup="maths();" contenteditable> </div></td>
        <td><div class="inputclass" id="total1" contenteditable> </div></td>

function maths()
{
    var qt = document.getElementById("quantity1").value;
    var up = document.getElementById("unitprice1").value;
    qtup = parseFloat((qt * up)) || 0;
    document.getElementById("total1").value = qtup;
}

Recommended Answers

All 3 Replies

I haven't done this with editable <div>s before, but usually you get a div's content by using div.innerHTML, not div.value. So changing your code to

function maths()
{
    var qt = document.getElementById("quantity1").innerHTML;
    var up = document.getElementById("unitprice1").innerHTML;
    qtup = parseFloat((qt * up)) || 0;
    document.getElementById("total1").innerHTML = qtup;
}

might work. Why are you using editable <div>s instead of just inputs? :o

got it. here i am using contenteditable for description column. so, i have the plan to use all rows 7c498ba6ffbce873cf7ac3a9a01fb9e2 in contenteditable..

Well I wouldn't know the downside of it right now, but it just feels somewhat off to me to use contenteditable divs for stuff that I usually use inputs and textareas for. Anyway, glad your problem has been solved ;).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.