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

160
Views
Valor de entrada específico

Estoy creando un sitio web. Quiero que cuando se ingrese un texto específico, en y <input> , y luego se envíe con <button> , javascript avise a la página y responda con algo específico. Ej: si la entrada ingresada es $ip , la función de alert() de js enviará su ip, o si hace $add 2 2 , alertará 2+2=4 .

html

 <form> <input class="text" id="txt"> <button id="btn" class="submit-btn" onclick="get()">submit</button> </form>

JS

 function get() { var inputVal = document.getElementById("txt").value; alert(inputVal); }; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede leer el valor de entrada cuando el formulario se ha enviado y hacer lo que quiera con el valor. como esto:

 function handleSubmit(event) { event.preventDefault(); const value = document.getElementById('txt').value.trim(); switch (value) { case '': break; case '$ip': alert('You IP:xxx'); break; case '$add 2 2': alert('2+2=4'); break; default: alert(value + ': is not a valid action'); } }
 <form onsubmit="handleSubmit(event)"> <input class="text" id="txt"> <button id="btn" class="submit-btn">submit</button> </form>

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!