Ik ben net begonnen met het maken van websites en ik heb nog niet veel gewerkt met JS dus dit zal waarschijnlijk een simpel probleem zijn, alleen weet ik niet wat het probleem is en met de search kom ik ook geen oplossingen vinden
Ik heb op mijn pagina een checkbox met 4 opties.
Als je op het plaatje klikt (logo.gif) moet hij een nieuwe pagina openen(in hetzelfde scherm),
maar welke pagina hij opent is afhankelijk van de checkbox...
Met deze code doet hij dus helemaal niks, ik weet (denk) dat de fout hier zit :
Ik heb op mijn pagina een checkbox met 4 opties.
Als je op het plaatje klikt (logo.gif) moet hij een nieuwe pagina openen(in hetzelfde scherm),
maar welke pagina hij opent is afhankelijk van de checkbox...
Met deze code doet hij dus helemaal niks, ik weet (denk) dat de fout hier zit :
maar ik weet niet precies wat er fout is.if (checkbox_form.checkbox[0].checked) {window.location.replace('blabla.htm'); }
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
| <html>
<title>TEST</title>
<body bgcolor="#33669c">
<FONT COLOR="#FFFFD6">
<script Language="JavaScript">
<!--
function welkepagina()
{
if (checkbox_form.checkbox[0].checked) {window.location.replace('blabla.htm'); }
if (checkbox_form.checkbox[1].checked) {}
if (checkbox_form.checkbox[2].checked) {}
if (checkbox_form.checkbox[3].checked) {}
}
function checkbox_checker()
{
// set var checkbox_choices to zero
var checkbox_choices = 0;
// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
{
// If a checkbox has been selected it will return true
// (If not it will return false)
if (checkbox_form.checkbox[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices > 1)
{
// If there were more than three selections made display an alert box
msg="You're limited to only 1 selection.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please remove " + (checkbox_choices-1) + " selection(s)."
alert(msg)
return (false);
}
if (checkbox_choices < 1 )
{
// If there were less then selections made display an alert box
alert("Please make a selection. \n" + checkbox_choices + " entered so far.")
return (false);
}
welkepagina();
return(true);
}
-->
</script>
<form method="get" action="#"
onsubmit="return checkbox_checker()" name="checkbox_form">
<input type="checkbox" value="1" name="checkbox">1<br>
<input type="checkbox" value="2" name="checkbox">2<br>
<input type="checkbox" value="3" name="checkbox">3<br>
<input type="checkbox" value="4" name="checkbox">4<br>
<input type=image src="logo.gif">
</form>
</FONT>
</body>
</html> |