Rob,
I tried to remove a part of the code but that works only once. It will
remove the checked box but when I enter the page again; check all the
boxes and save it won't save the settings. Here's my whole code to
explain:
=================== CODE START ==============================
<HTML>
<HEAD>
<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-control" CONTENT="no-cache">
<TITLE>Smart Download Taken Afvinken</TITLE>
<script language="javascript">
var zmdv=new Array(0,17,18,12,28,1,31,2,3,29,20,6,30,27,11)
var zmv = new Array();
zmv=zmdv;
if ((zmcv=getCookie("zoek"))!='*')
zmv=zmcv.split(';');
function getCookie (cookieNaam) {
var cname = cookieNaam + "=";
var i = 0;
while (i < document.cookie.length) {
var j = i + cname.length;
if (document.cookie.substring(i, j) == cname){
var leng = document.cookie.indexOf (";", j);
if (leng == -1) leng = document.cookie.length;
return unescape(document.cookie.substring(j, leng));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return "*";
}
function delCookie (cookieNaam)
{
document.cookie = cookieNaam + "=; expires= Thu, 01-Jan-70 00:00:01
GMT";
document.cookie = cookieNaam + "=; expires= Thu, 01-Jan-70 00:00:01
GMT; path=/";
return true;
}
function setCookie(cookieNaam, cookieInhoud){
var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 10000);
document.cookie = cookieNaam + "= " + escape (cookieInhoud) +";
expires=" + expiry.toGMTString()+ "; path/";};
function resetForm()
{
delCookie("zoek");
//window.location.reload();
top.location="index.htm";
}
function saveGegevens()
{
if(navigator.appName!="Microsoft Internet
Explorer"||parseInt(navigator.appVersion) >= 4){
zmv=new Array();
for(i=0; i<(aantalZm);i++)
{
// if(document.zoekm.first
.checked==true)
// { zmv[0]=document.zoekm.first.value;
eval('document.zoekm.check'+document.zoekm.first.value+'.checked=true')}
}
var j=0;
for(i=0; i<aantalZm;i++)
{
if(eval('document.zoekm.elements['+((i*2)+1)+'].checked')==true
&& document.zoekm.first.value != zmv[0])
zmv[++j]=document.zoekm.first.value;
}
zmcv=zmv.join(';');
setCookie("zoek",zmcv);
top.location="index.htm";}
else window.alert("Het afvinken van taken niet mogelijk met de versie
van uw browser (3.0)");
}
function doCheckboxes( f, tick ){
var el, els = f.elements;
var i = els.length;
while ( i-- ) {
el = els;
if ( 'input' == el.nodeName.toLowerCase()
&& 'checkbox' == el.type ){
el.checked
= tick;
}
}
alert("Klik 'Opslaan' om de wijzigingen definitief te maken...");
}
</script>
</HEAD>
<BODY bgcolor="#fffacd" text="#000000" link="#000000" vlink="#000000"
alink="#000000">
<center>
<form name="zoekm">
<table name=zoektabel width=80% BORDER=0 CELLSPACING=0 CELLPADDING=0>
<tr>
<td colspan="3"><FONT SIZE="2" FACE="Arial">Hieronder vindt u de taken
terug die dagelijk worden uitgevoerd.<br>
Wanneer u alle taken uit een blok heeft uitgevoerd kunt u de taak
afvinken.<br>
De Radiobutton geeft aan met welke taak u momenteel bezig bent.<br><br>
</td>
</tr>
<tr BGCOLOR=#006699>
<td colspan="3"><FONT SIZE="2" FACE="Arial"
COLOR="#FFFFFF"><center><B>Taken Afvinken</B></center></font></td>
</tr>
<tr BGCOLOR=#FFD991>
<td valign="TOP">
<script language="javascript">
document.write('<br><FONT SIZE="2" FACE="Arial"> <br>');
document.write('<input type=radio name=first value=17><input
type=checkbox name=check17><font size=2 face="Arial">CH1</font><br>');
document.write('<input type=radio name=first value=0><input
type=checkbox name=check0><font size=2 face="Arial">CH2</font><br>');
document.write('<input type=radio name=first value=1><input
type=checkbox name=check1><font size=2 face="Arial">CH3</font><br>');
document.write('<input type=radio name=first value=20><input
type=checkbox name=check20><font size=2 face="Arial">CH4</font><br>');
document.write('<input type=radio name=first value=18><input
type=checkbox name=check18><font size=2 face="Arial">CH5</font><br>');
document.write('<input type=radio name=first value=2><input
type=checkbox name=check2><font size=2 face="Arial">CH6</font><br>');
document.write('<input type=radio name=first value=26><input
type=checkbox name=check26><font size=2 face="Arial">CH7</font><br>');
document.write('<input type=radio name=first value=23><input
type=checkbox name=check23><font size=2 face="Arial">CH8</font><br>');
document.write('<input type=radio name=first value=24><input
type=checkbox name=check24><font size=2 face="Arial">CH9</font><br>');
document.write('<input type=radio name=first value=30><input
type=checkbox name=check30><font size=2 face="Arial">CH10</font><br>');
document.write('<input type=radio name=first value=31><input
type=checkbox name=check31><font size=2 face="Arial">CH11</font><br>');
document.write('<br>');
document.write('<br></td><td valign="TOP">');
document.write('<br><FONT SIZE="2" FACE="Arial"> <br>');
document.write('<input type=radio name=first value=5><input
type=checkbox name=check5><font size=2 face="Arial">DF1</font><br>');
document.write('<input type=radio name=first value=6><input
type=checkbox name=check6><font size=2 face="Arial">DF2</font><br>');
document.write('<input type=radio name=first value=7><input
type=checkbox name=check7><font size=2 face="Arial">DF3</font><br>');
document.write('<input type=radio name=first value=12><input
type=checkbox name=check12><font size=2 face="Arial">DF4</font><br>');
document.write('<input type=radio name=first value=14><input
type=checkbox name=check14><font size=2 face="Arial">DF5</font><br>');
document.write('<input type=radio name=first value=15><input
type=checkbox name=check15><font size=2 face="Arial">DF6</font><br>');
document.write('<input type=radio name=first value=16><input
type=checkbox name=check16><font size=2 face="Arial">DF7</font><br>');
document.write('<input type=radio name=first value=3><input
type=checkbox name=check3><font size=2 face="Arial"></font><br>');
document.write('<input type=radio name=first value=4><input
type=checkbox name=check4><font size=2 face="Arial"></font><br>');
document.write('<input type=radio name=first value=19><input
type=checkbox name=check19><font size=2 face="Arial"></font><br>');
document.write('<input type=radio name=first value=25><input
type=checkbox name=check25><font size=2 face="Arial"></font><br>');
document.write('<br></td><td valign="TOP">');
document.write('<br><FONT SIZE="2" FACE="Arial"> <br>');
document.write('<input type=radio name=first value=8><input
type=checkbox name=check8><font size=2 face="Arial">AI1</font><br>');
document.write('<input type=radio name=first value=21><input
type=checkbox name=check21><font size=2 face="Arial">AI2</font><br>');
document.write('<input type=radio name=first value=10><input
type=checkbox name=check10><font size=2 face="Arial">AI3</font><br>');
document.write('<input type=radio name=first value=27><input
type=checkbox name=check27><font size=2 face="Arial">AI4</font><br>');
document.write('<input type=radio name=first value=11><input
type=checkbox name=check11><font size=2 face="Arial">AI5</font><br>');
document.write('<input type=radio name=first value=9><input
type=checkbox name=check9><font size=2 face="Arial">AI6</font><br>');
document.write('<input type=radio name=first value=22><input
type=checkbox name=check22><font size=2 face="Arial">AI7</font><br>');
document.write('<input type=radio name=first value=13><input
type=checkbox name=check13><font size=2 face="Arial"></font><br>');
document.write('<input type=radio name=first value=28><input
type=checkbox name=check28><font size=2 face="Arial"></font><br>');
document.write('<input type=radio name=first value=29><input
type=checkbox name=check29><font size=2 face="Arial"></font><br>');
document.write('<input type=radio name=first value=32><input
type=checkbox name=check32><font size=2 face="Arial"></font><br>');
for(i=0;i<zmv.length;i++)
{
eval('document.zoekm.check'+zmv+'.checked=true');
}
aantalZm=document.zoekm.elements.length/2;
for(i=0;i<aantalZm;i++)
if
(zmv[0]==document.zoekm.first.value)document.zoekm.first.checked=true;
</script>
</td>
</tr>
<tr BGCOLOR=#FFD991><td colspan=6> </td></tr>
<tr BGCOLOR=#FFD991><td colspan=6 align="center">
<input type="button" value="Opslaan" onClick="saveGegevens();">
<input type="button" value="Taken Leegmaken" onclick="doCheckboxes(
this.form, false );">
<input type="button" value="Alles Afvinken" onclick="doCheckboxes(
this.form, true );">
<input type=button value="Terug naar Smart Download"
onClick="top.location='index.htm'">
</td></tr>
</table>
</form>
</center>
</BODY>
</HTML>
================= CODE END ============================
RobG schreef:
Rob,
Thanks that works fine.
There is only one problem I have to deal with. When I uncheck
all boxes I have to click save to write the settings topm y cookie.
When I do so the checkbox next to the radiobutton that is checked
gets checked again.
Because your code tells it to be checked, see below.
function saveGegevens()
{
if(navigator.appName!="Microsoft Internet
Explorer"||parseInt(navigator.appVersion) >= 4){
I don't think this does anything useful. As noted previously, test for
support for features actually used - trying to guess what may or may not
be supported based on very unreliable browser detection is likely going
to cause far more issues that it solves (if it solves anything at all).
In the above test, some non-IE browser of version 1 (say Firefox) may
well be refused support, even though the features required to support
your script are trivial.
Because page developers insist on using flawed logic such as the test
above, browser vendors make their browsers report whatever appName or
appVersion they feel like. Many allow users set their browser to
masquerade as whatever they want.
Test for document.forms support, though I'd be surprised if any browser
in current use would fail.
zmv=new Array();
for(i=0; i<(aantalZm);i++)
{
if(document.zoekm.first.checked==true)
{ zmv[0]=document.zoekm.first.value;
eval('document.zoekm.check'+document.zoekm.first.value+'.checked=true')}
}
I thought we discussed 'eval' before. It is totally unnecessary, don't
use it. Also using global variables for counters is bad practice, the
brackets around aantalZm are unnecessary, you don't need to compare to
'true' explicitly and a local variable to store the value of
document.zoekm will make code simpler.
The line that is checking the checkbox is commented below:
function saveGegevens()
{
if { ! document.forms ) return;
var f = document.zoekm;
var zmv = [];
for( var i=0; i<aantalZm; i++ )
{
if ( f.first.checked )
{
zmv[0] = f.first.value;
// This line here is setting a checkbox to checked
f.check[ f.first.value ].checked = true;
}
}
var j=0;
for(i=0; i<aantalZm;i++)
{
if(eval('document.zoekm.elements['+((i*2)+1)+'].checked')==true
&& document.zoekm.first.value != zmv[0])
zmv[++j]=document.zoekm.first.value;
}
Get rid of eval:
var j=0;
for( i=0; i<aantalZm; i++ )
{
if ( f.elements[ ((i*2)+1) ].checked )
&& f.first.value != zmv[0])
{
zmv[++j] = f.first.value;
}
}
zmcv=zmv.join(';');
setCookie("zoek",zmcv);
top.location="index.htm";}
else window.alert("Het afvinken van taken niet mogelijk met de versie
van uw browser (3.0)");
}
If you have no further use for the global variable zmcv, it doesn't need
to be created:
setCookie( 'zoek', zmv.join(';') );
top.location = 'index.htm';
}
Can this code be changed so it doesn't do that?
Yes.
function saveGegevens()
{
// Test for support for forms collection
if { ! document.forms ) return;
var f = document.zoekm;
var zmv = [];
for( var i=0; i<aantalZm; i++ )
{
if ( f.first.checked )
{
zmv[0] = f.first.value;
// This line here is setting a checkbox to checked
f.check[ f.first.value ].checked = true;
}
}
var j=0;
for( i=0; i<aantalZm; i++ )
{
if ( f.elements[ ((i*2)+1) ].checked )
&& f.first.value != zmv[0])
{
zmv[++j] = f.first.value;
}
}
setCookie( 'zoek', zmv.join(';') );
top.location = 'index.htm';
}