Example of checking and unchecking checkboxes.

I know this works in FF3 but not IE8.

<script type="text/javascript">
window.onload = function(){
	// new span for checkbox
	emaillink = document.createElement('span');
	// the element that contains the save button
	thegobutton = document.getElementById('controlPanel');
	// the contact checkbox
	emailcntct = document.getElementById('emailcntct');
	// the custom project field for report on.
	sendcontactemail = document.getElementById("userfield35");

	// display the send to contact checkbox by save button
	emaillink.innerHTML = '   <label style="font-weight:bold;">Send email to</label><input type="checkbox" name="sendemailto" id="sendemailto" value="hello world" />';
	thegobutton.appendChild(emaillink);

	// the checkbox that is by the save button. the actual <input> element
	// it's here and not up above with the other variables because it has to go after the innerHTML addition on the emaillink object.
	sendemailto = document.getElementById('sendemailto');

	emailcntct.onclick = function()
	{
		if(emailcntct.checked)
		{
			sendcontactemail.checked = true;
			sendemailto.checked = true;
		}
		else
		{
			sendcontactemail.checked = false;
			sendemailto.checked = false;
		}
	}

	sendcontactemail.onclick = function()
	{
		if(sendcontactemail.checked)
		{
			emailcntct.checked = true;
			sendemailto.checked = true;
		}
		else
		{
			emailcntct.checked = false;
			sendemailto.checked = false;
		}
	}

	sendemailto.onclick = function()
	{
		if(sendemailto.checked)
		{
			sendcontactemail.checked = true;
			emailcntct.checked = true;
		}
		else
		{
			sendcontactemail.checked = false;
			emailcntct.checked = false;
		}
	}
}
</script>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.