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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -