Undefined value problem

I have a question abbout video assignment, when user enter a fruit and it pushs to array.
I always gat undefened value from input textbox? Anybody know why?

  <input placeholder="WriteFruit" type="text" id="inpTxt"/>
  <button id="buttonFr">Add a fruit</button>

    <script>
            var fruits=["Banana", "Orange"];
            var list= $("#fruitOrdList");

            $("#buttonFr").click(function(){
        /*      fruits.push($("inpTxt").val()); */
              var adFruit = $("inpTxt").val();
              alert(adFruit);
              console.log("ButtonPushed");
            });

Looks like you’ve missed the ‘#’ when querying its value. It should be $("#inpText").val()

:joy::sweat_smile:thanks man

1 Like