Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  135] [ 1]  / answers: 1 / hits: 34960  / 10 Years ago, mon, october 13, 2014, 12:00:00

I was wondering if it was possible to add an id to a variable in JavaScript.



Like This...



JavaScript:



var name = #userid;


HTML:



<input type=text id=userid />


... So I want to set a variable to the input in the HTML. I have tried using



getElementById()


I'd like it so when a userid is entered into the input, I would like to set that to a variable in JS.



Much Appreciated...



Thank You, James Noon


More From » html

 Answers
4

This will update a global variable called name, when the value in the textbox is changed (but only once the user has left the control, by clicking or tabbing out)...



<input type=text id=userid onchange=name=this.value; />


If you want to update the global variable at some other time (a different event) then you want this script...



var name = document.getElementById(userid).value;

[#69147] Thursday, October 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lidialyrick

Total Points: 737
Total Questions: 104
Total Answers: 89

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
lidialyrick questions
;