Help me learn how to use .value in Javascript please! | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Help me learn how to use .value in Javascript please!

Hello, I am a Spaniard from Central America, I am currently learning Javascript But I have a problem because when using the .value in an element, whether input or anything, it gives me an error, Currently I'm using a Spanish to English translator but it said something like I couldn't accept or read indefinite things or null, This is my code that I use (this is an example) const input = document.querySelector("input").value; const btn = document.querySelector("button"); function useMe() { If (input == " ") { Alert("???"); } } btn.onclick.useMe /* Even in btn.onclick.use I get an error Saying the same thing that I can't read null things and that...*/

5th May 2024, 11:27 PM
SoyEspañolSalvadoreño777
SoyEspañolSalvadoreño777 - avatar
9 Réponses
+ 3
I understand; when I was a beginner, I had the same concerns. However, I found that the real joy of coding lies in problem-solving and learning how everything works. If the .value attribute is giving you the most trouble, I suggest learning more about its correct uses. Try other tutorials or read articles about its uses. Or watch some youtube videos.. Until you can grasp the concept. If you need further assistance, let me or the rest of the community know, and we will do our best to help.
6th May 2024, 4:09 AM
Chris Coder
Chris Coder - avatar
+ 3
Hi if you goal is to take an input and display ??? if the input is empty, use prompt() to take input. x  = prompt() if(x == "") {   alert("???"); } There are many uses for value in javascript.  For example: - The value attribute specifies the value of an <input> element.  <input type="text" id="name" name="name" value="Soy"><br> The value property sets or returns the value of an attribute. To return the value of <input> element to console we can do this.  const name = document.getElementById('name'); console.log(name.value); To change the value of <input> element with id we do this.  document.getElementById("name").value = "Chris Coder"; Find out more uses for value here: https://www.w3schools.com/
6th May 2024, 3:28 AM
Chris Coder
Chris Coder - avatar
+ 2
Thank you very much Chris for your help and support, I will continue looking for answers and continue learning, Greetings and good night from Central America :)
6th May 2024, 4:13 AM
SoyEspañolSalvadoreño777
SoyEspañolSalvadoreño777 - avatar
+ 1
Thank you very much Chris, For your help, I understand your idea and in question to the first question, I feel very pressured to learn about .value since all the projects that my mind can imagine, They have a related input, I already know about conditional loops functions and a little about Dom and arrays, But I feel discouraged knowing that the prompt is a similar measure But not at all the same To an input, And stopping thinking about it, I have a question and that is that these input attributes can help , since I knew that the ones before value were form data..
6th May 2024, 3:43 AM
SoyEspañolSalvadoreño777
SoyEspañolSalvadoreño777 - avatar
+ 1
In my mind.. There are many ideas of... Shopping list with Javascript... Or a mini notepad, But.. I feel like those ideas are erased and frustrated because the .value doesn't work...It makes me wonder... Have I wasted my time on something that wasn't for me? Should I abandon this knowing what it cost me? There is still no clear answer in my mind But my mind is on both sides, leaving and Not leaving...
6th May 2024, 3:48 AM
SoyEspañolSalvadoreño777
SoyEspañolSalvadoreño777 - avatar
+ 1
You're welcome SoyEspañolSalvadoreño777 😊
6th May 2024, 4:16 AM
Chris Coder
Chris Coder - avatar
+ 1
MDN is also a great resource to use
6th May 2024, 4:22 AM
Canvas
Canvas - avatar
+ 1
8th May 2024, 12:43 AM
Chris Coder
Chris Coder - avatar
0
Hey Chris! I finally found the solution! I have to use the Window.onload for it to work, Here the code: window.onload = function allYourcodeHere() { }
7th May 2024, 11:17 PM
SoyEspañolSalvadoreño777
SoyEspañolSalvadoreño777 - avatar