-3

I want to put a word in an <input> and have a changed output. For example,

Input = Peter

Output = From Peter Parker

function impf1() {
  var first = document.getElementById("imp1").value;
  var out1 = "print(" + first + ")";
  return out1;
  console.log(out1);
  window.alert(out1);
  return false;
}
<h5></h5>

<div class="hr">
  <hr />
</div>
<h3></h3>

<center><select>
<option value="python">Python</option>
</select></center>

<center>
  <button onclick="impf1()">GET CODE</button>
</center>

This is the desired output:

desired output

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
JJ Jr.
  • 1
  • 1
  • 2
    Possible duplicate of [How do I change the text of a span element in JavaScript](https://stackoverflow.com/questions/1358810/how-do-i-change-the-text-of-a-span-element-in-javascript) – Sebastian Simon Apr 10 '18 at 10:29
  • 1
    You are selecting element by id but there are no elements with id in your html – aMJay Apr 10 '18 at 10:33

1 Answers1

0

function impf1() {
  var first = document.getElementById("imp1").value;

  var out1 = "print(" + first + ")";
  document.getElementById("showdata").textContent="From "+first;
  return out1;
  console.log(out1);
  window.alert(out1);
  return false;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<h5></h5>

<div class="hr">
  <hr />
</div>
<h3></h3>

<center><select>
<option  id= "imp1" value="Peter Parker">Peter</option>
</select></center>

  <button onclick="impf1()">GET CODE</button>
</center>

<center>
  <div id="showdata"></div>
</center>
Akhil Singh
  • 700
  • 6
  • 17