Help me learn how to use .value in Javascript please! | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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
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