[Javascript] Checkbox Problems

Timothy White weirdit at gmail.com
Mon Jul 4 19:57:13 CDT 2005


Hi. New to this list so please don't kill me ;)[1]

I have a little problem that I'm trying to solve in javascript. 
</short_description>Basically I'm building a self propagating page
that doesn't rely on server side (except for the initial
page).</short>

<long_description>To do this I have a list of checkboxes, the user
selects the ones they want, then click a button which 'pastes' the src
of the page into a textbox, javascript and all. The entention that
they can then select the code in the textbox and paste it into there
website, blog, etc and then someone who views it can change the
checkbox selections, click the button and get there own copy to paste
on their site....</long_description>

<problem>element.checked is only held in browser memory. attribute
checked doesn't take values, it's presences defines the initial
state</problem>

So basically I can get the checked state of a checkbox with the
checked attribute (node). I can also set the HTML attribute 'checked'
so that when the page loads the checkbox is checked. But if I set the
HTML attribute to checked, how can I remove it? Remember that it
doesn't take a value, so setting it to false does nothing.

So currently the code I have to get the HTML is as below
---
  srcbox = document.getElementById('src');
  checkboxs = document.forms.quiz.quest;
  for(c=0; c< checkboxs.length; c++){
     if(checkboxs[c].checked) checkboxs[c].setAttribute("checked", "");
  }
  srcbox.value = document.documentElement.innerHTML;
---
I know need to and an else statement to the if statement that says
something like unsetAttribute("checked") (I know that unsetAttribute
isn't valid)

Anyone know how to do this? Maybe a regex parse of the input field?

Thanks

Tim
[1] Cause I'm really not a newbie, I'm all over the internet, mailing
lists, irc...



More information about the Javascript mailing list