Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  143] [ 3]  / answers: 1 / hits: 48444  / 12 Years ago, thu, may 3, 2012, 12:00:00

I am used to doing this in jQuery



$('#RememberMe').attr('checked', true); 


but I can't remember how to do it in Javascript I thought that



document.getElementById(RememberMe).value = True; 


would work, but it doesn't, it changes the value but does not create the visual check on the html.



I am trying to set the checkbox to on by default. here is the html



<input id=RememberMe name=RememberMe type=checkbox value=false />   

More From » jquery

 Answers
2

To change checkbox state try this:



document.getElementById(RememberMe).checked = true;


If you need to change the value of checkbox as an input element use:



document.getElementById(RememberMe).value = New Value;


However, you can set default value and state in HTML markup:



<input id=RememberMe name=RememberMe type=checkbox value=The Value checked=checked /> 

[#85812] Wednesday, May 2, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristinsonjab

Total Points: 364
Total Questions: 98
Total Answers: 98

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
kristinsonjab questions
Fri, Mar 4, 22, 00:00, 2 Years ago
Fri, Jan 22, 21, 00:00, 3 Years ago
Fri, Aug 14, 20, 00:00, 4 Years ago
;