How do I get the value of the input?

  • 0
    First time in my life trying to link js file and html
    And I'm in pain
    The bottom line - I wanted to have an input field and a send button
    and when the button was clicked, the values ​​from the input field were passed to the function in the js file.
    And as a result, after 40 minutes, I found a solution that is very similar to the correct one that DOES NOT WORK ((((((((
    it works in jsfiddle, in browser it gives error
    what's my problem?

    JavaScript Cole Gardner, Feb 7, 2019

  • 3 Answers
  • 0
    Anonymous

  • 0
    Why wasn't the script included? Before the closing body tag.

    Put the line

    & lt; script src = "path to js file" & gt; & lt; / script & gt;
    Anonymous

  • 0
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>
    <input id="elem1" type="text" name="quantity" placeholder="количество">
    <input id="butt" type="button" value="кнопка"><br>
    <div id="str"></div>
    <script>
    let butt=document.getElementById('butt')
    butt.onmousedown=()=>{
    document.getElementById("str").innerHTML="Вы ввели"+document.getElementById('elem1').value;
    }
    </script>
    </body>
    </html>
    Keira Martinez

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!