astralaaron Posted February 13, 2010 Share Posted February 13, 2010 how do you go about detecting that? Link to comment Share on other sites More sharing options...
jeffman Posted February 13, 2010 Share Posted February 13, 2010 Your question could be more clear. Maybe you're asking about the onchange property? You can assign an event handler function to that and it will fire when the box is checked or unchecked. The function itself can get the checked state in this.checked, which will return true or false. Link to comment Share on other sites More sharing options...
astralaaron Posted February 13, 2010 Author Share Posted February 13, 2010 Your question could be more clear. Maybe you're asking about the onchange property? You can assign an event handler function to that and it will fire when the box is checked or unchecked. The function itself can get the checked state in this.checked, which will return true or false.yeah that sounds right, I meant I want to have a function execute when you check the box or uncheck.thanks Link to comment Share on other sites More sharing options...
jeffman Posted February 13, 2010 Share Posted February 13, 2010 Yeah, that's your change handler. Link to comment Share on other sites More sharing options...
astralaaron Posted February 13, 2010 Author Share Posted February 13, 2010 having some trouble with this, it turns the color yellow but when I uncheck it, it doesnt change to red..its confusing too, I thought when I checked it, it would change red. then uncheck would change to yellow. function lightup(id) { elm = document.getElementById(id); if(document.delr.id.checked == true) { elm.bgColor = "red"; } else { elm.bgColor = "yellow"; } }<form name="delr" ><tr id="x1"><td><input type="checkbox" name="x1" onchange="lightup('x1');" /></td></tr>*EDIT: when I add alert(document.delr.id.checked); to the function it alerts: undefined.. Link to comment Share on other sites More sharing options...
jeffman Posted February 13, 2010 Share Posted February 13, 2010 I almost never refer to form elements using dot notation. It has history, but it's not standard. Better to use an id and then document.getElementById instead. Some browsers (like IE) can get confused if elements have the same name and id. I forget the different ways it can object, or if this is one of them, but it's best to play it safe.Did you print the actual structure of this thing? With the form tag coming inside a table, but before a table row element? That can only lead to trouble. Nothing is permitted to exist between rows.With every change you make, alert the reference to your input element until you see that it's valid. Then test the rest of the code. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 15, 2010 Share Posted February 15, 2010 I find that IE tends to do weird things with the onchange event of radios and checkboxes. I use the onclick event instead. Link to comment Share on other sites More sharing options...
jeffman Posted February 15, 2010 Share Posted February 15, 2010 I find that IE tends to do weird things with the onchange event of radios and checkboxes. I use the onclick event instead.Yeah, I'd forgotten. My bad. onclick works, though. Good catch. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.