Uncaught TypeError: Cannot set property 'value' of null

前端 未结 8 940
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 07:58

I\'m trying to pass the entered text to the controller using an ajax request. But i\'m getting athe error \"Uncaught TypeError: Cannot set property \'value\' of null \" whe

8条回答
  •  旧巷少年郎
    2020-12-05 08:34

    I knew that i am too late for this answer, but i hope this will help to other who are facing and who will face.

    As you have written h_url is global var like var = h_url; so you can use that variable anywhere in your file.

    • h_url=document.getElementById("u").value; Here h_url contain value of your search box text value whatever user has typed.

    • document.getElementById("u"); This is the identifier of your form field with some specific ID.

    • Your Search Field without id

    • Alter Search Field with id

    • When you click on submit that will try to fetch value from document.getElementById("u").value; which is syntactically right but you haven't define id so that will return null.

    • So, Just make sure while you use form fields first define that ID and do other task letter.

    I hope this helps you and never get Cannot set property 'value' of null Error.

提交回复
热议问题