PDA

View Full Version : function countChoices(obj) error



mskocabay
Aug 9th, 2007, 04:51 PM
i use tihis function for checkboxlimit.



<SCRIPT LANGUAGE="JavaScript">
function countChoices(obj) { //checkbox kontrol dil
max = 3; // max. number allowed at a time

box1 = obj.form.lang[0].checked;
box2 = obj.form.lang[1].checked;
box3 = obj.form.lang[2].checked;
box4 = obj.form.lang[3].checked;
box5 = obj.form.lang[4].checked;
box6 = obj.form.lang[5].checked;
box7 = obj.form.lang[6].checked;
box8 = obj.form.lang[7].checked;
box9 = obj.form.lang[8].checked;
box10 = obj.form.lang[9].checked;

count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0)+ (box4 ? 1 : 0)+ (box5 ? 1 : 0)+ (box6 ? 1 : 0)+ (box7 ? 1 : 0)+ (box8 ? 1 : 0)+ (box9 ? 1 : 0)+ (box10 ? 1 : 0);
// If you have more checkboxes on your form
// add more (box_ ? 1 : 0) 's separated by '+'

if (count > max) {
alert("En fazla " + max + " dil seçebilirsiniz!");
obj.checked = false;
}

}
</script>

but there was a javascript error
'form.lang.0.checked' null or no object

my form code

<td width="93">
<input type=checkbox value=İngilizce
name=lang[] id="lang[]" onClick="countChoices(this)">
<span class="style13">&nbsp;<span class="style7">İngilizce
<br>
<input type=checkbox value=Almanca
name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;Almanca<br>
<input type=checkbox
value=Fransızca name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;Fransızca<br>
<input type=checkbox value=İtalyanca
name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;İtalyanca<br>
<input type=checkbox value=İspanyolca name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;İspanyolca</span></span></td>
<td width="93"><span class="style13"><span class="style7">
<input type=checkbox value=Japonca name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;Japonca<br>
<input type=checkbox value=Arapça
name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;Arapça<br>
<input type=checkbox value=Çince name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;Çince<br>
<input type=checkbox value=Rusça name=lang[] id="lang[]" onClick="countChoices(this)">
&nbsp;Rusça<br>
<input type=checkbox value=Diğer
name=lang10 id="lang10" onClick="countChoices(this)">
&nbsp;Diğer</span></span></td>

i have to use lang[] array for php

how can i fix this problems
thanks

Arty Effem
Aug 9th, 2007, 05:28 PM
but there was a javascript error
'form.lang.0.checked' null or no object

my form code
[CODE] <td width="93">
<input type=checkbox value=İngilizce
name=lang[] id="lang[]"
i have to use lang[] array for php

how can i fix this problems
thanks
Try


obj.form['lang[]'][0]

/* or */

obj.form.elements['lang[]'][0]

vwphillips
Aug 9th, 2007, 05:33 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">


function ValidateCkBox(obj,max){
var eles=obj.form.elements;
var cnt=0;
for (var zxc0=0;zxc0<eles.length;zxc0++){
if (eles[zxc0].name==obj.name){
if (eles[zxc0].checked) cnt++;
}
}
if (cnt>max){
alert('En fazla '+min+' to '+max +' dil seçebilirsiniz!');
return false;
}
return false;
}

</script>
</head>

<body>
<form >
<table>

<td width="93">
<input type=checkbox value=İngilizce
name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
<span class="style13">&nbsp;<span class="style7">İngilizce
<br>
<input type=checkbox value=Almanca
name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;Almanca<br>
<input type=checkbox
value=Fransızca name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;Fransızca<br>
<input type=checkbox value=İtalyanca
name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;İtalyanca<br>
<input type=checkbox value=İspanyolca name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;İspanyolca</span></span></td>
<td width="93"><span class="style13"><span class="style7">
<input type=checkbox value=Japonca name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;Japonca<br>
<input type=checkbox value=Arapça
name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;Arapça<br>
<input type=checkbox value=Çince name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;Çince<br>
<input type=checkbox value=Rusça name=lang[] id="lang[]" onClick="ValidateCkBox(this,3);">
&nbsp;Rusça<br>
<input type=checkbox value=Diğer
name=lang10 id="lang10" onClick="ValidateCkBox(this,3);">
&nbsp;Diğer</span></span></td></table>

</form>

</body>

</html>

mskocabay
Aug 10th, 2007, 07:45 AM
thanks