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

  • 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;

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

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