Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Entrada con un valor fijo

Quiero crear una tabla con un precio fijo, un campo de entrada donde alguien pueda ingresar un valor y una columna con el total (precio * cantidad)

El problema que tengo es que el código que escribí funciona pero solo con números enteros. no se lee después de la coma. Entonces, si ingreso un precio de 4.39, se calcula con 4.

Además, si configuro el tipo en "decimal" o "número", no funciona.

 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.js"></script> <script type="text/javascript"> $(function () { $('.price,.quantity').on('keyup', function () { var row = $(this).closest('tr'); var price = $(row).find('.price').val() == '' ? 0 : $(row).find('.price').val(); var quantity = $(row).find('.quantity').val() == '' ? 0 : $(row).find('.quantity').val(); $(row).find('.total').val(parseInt(isNaN(price) ? 0 : price) * parseInt(isNaN(quantity) ? 0 : quantity)); }); }); </script> </head> <body> <div> <table> <tr> <th>Name</th> <th>Price</th> <th>Quantity</th> <th>Total</th> </tr> <tr> <td>Chai</td> <td><input type="text" class="price" value="1.39" /></td> <td><input type="text" class="quantity" /></td> <td><input type="text" class="total" /></td> </tr> <tr> <td>Chang</td> <td><input type="text" class="price" /></td> <td><input type="text" class="quantity" /></td> <td><input type="text" class="total" /></td> </tr> <tr> <td>Aniseed Syrup</td> <td><input type="text" class="price" /></td> <td><input type="text" class="quantity" /></td> <td><input type="text" class="total" /></td> </tr> </table> </div> </body> </html>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede agregar un atributo de readonly a sus input fields para que non-editable .

 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.js"></script> <script type="text/javascript"> $(function () { $('.price,.quantity').on('keyup', function () { var row = $(this).closest('tr'); var price = $(row).find('.price').val() == '' ? 0 : $(row).find('.price').val(); var quantity = $(row).find('.quantity').val() == '' ? 0 : $(row).find('.quantity').val(); $(row).find('.total').val(parseInt(isNaN(price) ? 0 : price) * parseInt(isNaN(quantity) ? 0 : quantity)); }); }); </script> </head> <body> <div> <table> <tr> <th>Name</th> <th>Price</th> <th>Quantity</th> <th>Total</th> </tr> <tr> <td>Chai</td> <td><input type="text" class="price" /></td> <td><input type="text" class="quantity" /></td> <td><input type="text" class="total" readonly/></td> </tr> <tr> <td>Chang</td> <td><input type="text" class="price" /></td> <td><input type="text" class="quantity" /></td> <td><input type="text" class="total" readonly/></td> </tr> <tr> <td>Aniseed Syrup</td> <td><input type="text" class="price" /></td> <td><input type="text" class="quantity" /></td> <td><input type="text" class="total" readonly/></td> </tr> </table> </div> </body> </html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!