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

159
Views
Specific input value

I am creating a website. I want that when a specific text is entered, in and <input>, and then submited with <button>, javascript alerts the page and reply with a specific thing. Ex: if the entered input is $ip, the alert() function of js will send your ip, or like if you do $add 2 2, it will alert 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

You can read the input value when form has submitted and do whatever you want with the value. like this:

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!