+ 8

Assignment in JavaScript

How can i assign the value of an element without using a variables. For example: x=0; x+=10 How can i use something short like: x=document.getElementById("input"); x.value.=toUpperCase() /*👆👆This wont work*/ Lets say i have this: <input id="input"> <script> </script>

13th Sep 2020, 1:38 PM
Goke Ekundayo
Goke Ekundayo - avatar
6 Réponses
+ 21
Well, it really depends on, what you actually want. You can assign a value to any element selected by ID, using .value property. For example: document.getElementById("input").value = "Gekoda"; Or you can add an attribute value=" Gekoda. [[[[[[I N A C T I V E]]]]]] " to any input HTML element. Like so ↓↓↓: <input type="text" value="Gekoda"/> Remember! Input receives a string of text from a user, not a number. Also upperCase() is NOT a value. It's a .style.textTransform property. You can assign it in the same way as .value .
13th Sep 2020, 4:11 PM
🇺🇦 Drake CDR 🇺🇦
🇺🇦 Drake CDR 🇺🇦 - avatar
+ 16
Another variant requires transition variable to perform .toUpperCase() method: https://code.sololearn.com/W3Q9UBM2CaIl/?ref=app This should work best for your case 😉.
13th Sep 2020, 5:31 PM
🇺🇦 Drake CDR 🇺🇦
🇺🇦 Drake CDR 🇺🇦 - avatar
+ 15
A short version, based on the second part of your question. If you have selected the element X and you want to style it, this will work 👇: document.getElementById("x").style.textTransform = "uppercase";
13th Sep 2020, 4:27 PM
🇺🇦 Drake CDR 🇺🇦
🇺🇦 Drake CDR 🇺🇦 - avatar
+ 7
Ok thanks. I understand
13th Sep 2020, 4:35 PM
Goke Ekundayo
Goke Ekundayo - avatar
+ 3
Define all the variable at once in the start of script. <script> Var a, b, c, d ; And then use as a= document. Getelementbyid("input") ; You can Do it like that.
13th Sep 2020, 1:49 PM
Divya Mohan
Divya Mohan - avatar
+ 3
x=document.getElementById("input").value.toUpperCase(); Or x = document.getElementById("input"); x.value = x.value.toUpperCase(); += also works but adds 2times value like 'a' to 'aA'
13th Sep 2020, 2:37 PM
Jayakrishna 🇮🇳