SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Aug 1, 2003, 04:55 #1
- Join Date
- Sep 2002
- Location
- UK
- Posts
- 573
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do you check/uncheck a checkbox using Javascript
Can anyone tell me how you check or uncheck a checkbox using javascript?
-
Aug 1, 2003, 05:00 #2Code:
document.[form name].[checkbox name].checked = true;
. Set it to false to uncheck the box.
-
Aug 1, 2003, 05:27 #3
- Join Date
- Jun 2001
- Location
- Before These Crowded Streets
- Posts
- 9,446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hey vinnie, along these same lines....how would you refer to this element using getobjectbyid[]?
-
Aug 1, 2003, 05:47 #4
- Join Date
- Sep 2002
- Location
- UK
- Posts
- 573
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ta very much
-
Aug 1, 2003, 07:43 #5
Originally Posted by Sketch
JS
Code:document.getElementById("myCheckbox").setAttribute("checked", "checked");
Code:<label for="myCheckbox">Restart server?</label> <input type="checkbox" name="myCheckbox" id="myCheckbox" />
.
-
Aug 1, 2003, 07:56 #6
- Join Date
- Jun 2001
- Location
- Before These Crowded Streets
- Posts
- 9,446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No that's what I meant. It just seems like using getelementbyid always coughs for form fields and I haven't been able to figure it all out yet.
-
Aug 1, 2003, 08:02 #7
Originally Posted by Sketch
-
Aug 1, 2003, 08:27 #8
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
True vinnie, but I still prefer the collections to the literal properties
this
document.forms['form1'].elements['input1']
rather than this
document.form1.input1
Sure, it's more typing, but FAR less problematic - and I'm not really that lazy to type a dozen extra characters
-
Aug 1, 2003, 09:05 #9
Originally Posted by beetle
. The problem with the document.forms[] collection (or the shortened document.[form name] sytnax) as I understand it is that when XHTML is sent to the browser as XML the scripts using those collections will fail though.
Bookmarks