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

107
Views
borrar el campo de entrada cuando se ingresa texto en otro campo de entrada

Tengo un convertidor de divisas, que consta de dos campos y un botón. En el primer campo escribo la cantidad que quiero convertir, en el segundo campo obtengo el resultado de la conversión. La pregunta es: cuando escribo texto en el primer campo, ¿cómo puedo limpiar el texto del segundo campo con el resultado de la conversión? ¿Usando una función Javascript / Jquery?

Gracias por adelantado.

Este es mi código:

 function convertiLireInEuro() { var importoInserito = $('#txtLireEuro').val(); importoInserito = importoInserito.replace(/,/g, '.'); var lire = parseFloat(importoInserito) var euro = lire * 1000 / 1936.27 euro = euro.toFixed(2); euro = Math.round(euro); $('#txtConversione').val(euro); }

HTML:

 <input type="text" id="txtLireEuro" name="txtLireEuro" style="text-align:right" onkeypress="return onlyNumbers(event);" /> &nbsp;000&nbsp;₤ <input value="Converti in Euro" type="button" id="btnLireEuro" name="btnLireEuro" style="margin-left: 20px" onclick="convertiLireInEuro();highlightAndCopyText();"/> <input type="text" id="txtConversione" name="txtConversione" style="text-align:right;margin-left:20px" readonly />&nbsp;€ <span class="Label" style="margin-left:12px">(importo già arrotondato all'intero e incollabile nel campo desiderato)</span>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Ya tiene un detector de eventos onkeypress llamado onlyNumbers . Simplemente puede poner $('#txtConversione').val = ""; en esa función.

about 4 years ago · Juan Pablo Isaza Report

0

código HTML

 <body> <input type="text" id="input_box"> <input type="text" id="result_box"> </body>

Código JQuery

 <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function() { $("#input_box").keydown(function(){ $("#result_box").val(""); }) }); </script> <body> <input type="text" id="input_box"> <input type="text" id="result_box"> </body>

Cuando "Input_box" se enfoca en hacer clic, result_box borrará su valor.

about 4 years ago · Juan Pablo Isaza Report

0

Esto es lo que necesita, publico un fragmento de codificación. Tengo 2 campos, typing-field y field-to-reset . Si primero completa el field-to-reset con algo de texto y luego comienza a escribir en el typing-field el field-to-reset se restablecerá.

 let typing = document.getElementById("typing-field"); let reset = document.getElementById("field-to-reset"); typing.addEventListener("keydown", () => { reset.value = ""; })
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div>Typing field:</div> <input id="typing-field" type="text"> <div>Field to reset:</div> <input id="field-to-reset" type="text"> </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!