+ 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>
6 odpowiedzi
+ 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 .
+ 16
Another variant requires transition variable to perform .toUpperCase() method:
https://code.sololearn.com/W3Q9UBM2CaIl/?ref=app
This should work best for your case 😉.
+ 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";
+ 7
Ok thanks. I understand
+ 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.
+ 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'