html - How to multiple (a*b) two input text value and show it Dynamicly with text change in javascript? -
i want show money customer must pay , inputs :
<input type="text" class="form-control" placeholder="cost " id="txt" name="credit"> <input type="text" class="form-control" placeholder="quantity" id="txt" name="limit">
when input text changing want show total cost (quantity*cost) in <p>
tag dynamicly how can javascript?
all of above generate errors if both boxes blank . try code , tested , running .
<script> function calc() { var credit = document.getelementbyid("credit").value; var limit = document.getelementbyid("limit").value; if(credit == '' && limit != '') { document.getelementbyid("cost").innerhtml = parseint(limit); } else if(limit == '' && credit != '') { document.getelementbyid("cost").innerhtml = parseint(credit); } else if(limit!= '' && credit!= '') { document.getelementbyid("cost").innerhtml = parseint(limit) * parseint(credit); } else { document.getelementbyid("cost").innerhtml = ''; } } </script> </head>
<input type="number" value="0" min="0" class="form-control" placeholder="cost" id="credit" name="credit" onkeyup="calc();"> <input type="number" value="0" min="0" class="form-control" placeholder="quantity" id="limit" name="limit" onkeyup="calc();"> <p id="cost"></p>
Comments
Post a Comment