How to get the input field Value and put it in a paragraph?

404 views Asked by At

I want to get the value of an input field and put the value in between a paragraph and a <strong></strong> tag.

$(document).ready() {
  $("#submit").on("click", function() {
    let inputval = $("#name").val();
    $(".inputvalue").val(inputval);
  })
}
<!DOCTYPE html>
<html lang="de">

<head>
  <meta charset="UTF-8">
  <title>jQuery</title>
</head>

<body>
  <header>
    <h1>Jquery</h1>
  </header>
  <main>
    <section>
      <label for="name">Name</label>
      <input type="text" id="name">
      <input type="submit" id="submit">
      <p class="inputvalue">Hallo <strong>here goes the value of the input field</strong></p>
  </main>
  <link rel="stylesheet" href="/lib/css/styleswebd06.css">
  <script src="/lib/jquery.min.js"></script>
  <script src="/lib/js/appwebd06.js"></script>
</body>

</html>

i tried to get the value of the input field #name in class .inputvalue to geht the text hallo inputvalue

3

There are 3 answers

1
Faissal Wahabali On
$(".inputvalue strong").text(inputvalue);
0
silence1979g On
$(".inputvalue").html('HELLO <strong>' + inputval + '</strong>');

Thank you very much.

0
SelVazi On

Could you try this :

$(document).ready()
{

    $("#submit").on("click", function () {
        let inputval = $("#name").val();
        $(".inputvalue").html('HELLO <strong>' + inputval + '</strong>');
    })
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="de">
<head>  
    
    
    

    <meta charset="UTF-8">
    <title>jQuery</title>

</head>
<body>
<header><h1>Jquery</h1></header>
<main>
    <section>
        <label for="name">Name</label>
        <input type="text" id="name">
        <input type="submit" id="submit">
        <p class="inputvalue">Hallo <strong>here goes the value of the input field</strong></p>
</main>
<link rel="stylesheet" href="/lib/css/styleswebd06.css">
    <script src="/lib/jquery.min.js"></script>
        <script src="/lib/js/appwebd06.js"></script> 

</body>
</html>