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

271
Views
Can i put 2 values in 1 textbox in javascript?

Is there a way to put 2 values in 1 text box using javascript? another question just dont answer if dont antw to, may i know how to if-else numbers like (enter-age 18-60 only)

<script>
function greeting() {
var name; 
var name = name.value;
document.getElementById("greeting1").value = name;
var greet;
var timep = time.value;
if (timep == "M") {
    greet = "Good Morning";
    document.getElementById("greeting1").value = greet;
    }
    else if (timep == "E") {
    greet = "Good Evening";
    document.getElementById("greeting1").value = greet;
    }
    else{
    alert("Not Allowed")
    }
    }       
</script>
<body>
<p>Enter Name::</p> <input type="text" id="name"  />
<p>Enter Time Period [M/E]::</p> <input type="text" id="time"  />
<button onclick="greeting()">TRY</button>
<input type="text" id="greeting1" readonly  />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To append multiple values to same text field use .value += greet

function greeting() {
  var name = document.getElementById("name").value;
  var greet;
  var timep = time.value;

  if (timep == "M") {
    greet = "Good Morning";
  } else if (timep == "E") {
    greet = "Good Evening";
  } else {
    alert("Not Allowed")
  }
  
  document.getElementById("greeting1").value = greet + ' ' + name;
}
<p>Enter Name::</p> <input type="text" id="name" />
<p>Enter Time Period [M/E]::</p> <input type="text" id="time" />
<button onclick="greeting()">TRY</button>
<input type="text" id="greeting1" readonly />


Solution without entering time:

function greeting() {
  var name = document.getElementById("name").value;
  var hour = new Date().getHours();
  var greeter = document.getElementById("greeting1");
  
  greeter.value = name;

  if (hour < 12) {
    greeter.value += " Good Morning";
  } else {
    greeter.value += " Good Evening";
  }
}
<p>Enter Name::</p> <input type="text" id="name" placeholder="Name"/>
<button onclick="greeting()">TRY</button>
<input type="text" id="greeting1" readonly />

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!