hello

i have this function to check all the checkboxes in the form.

function msgSCheck(){
chk = document.msgFList.msgCList;
if(document.msgFList.msgCheckCtrl.checked==true){
for (i = 0; i < chk.length; i++)
chk.checked = true ;
}else{
for (i = 0; i < chk.length; i++)
chk.checked = false ;
}
}

and input checkboxes like this one!

<input type="checkbox" name="msgCList" value="93287" />

like that works fine.
but i want to change the name in to name="msgCList[]" so i can get the value from al the checkboxs in that form..

chk = document.msgFList.msgCList[];
using this to check all the boxes i get an error.. what i need to do ?! please help me :) thanks

Recommended Answers

All 6 Replies

Member Avatar for rajarajan2017

Even you do this method, it is not possible to check all the box in a single line, again you are going to check the length like your above code. So both will same.

hi rajarajan , yes it works with the first one :) but if i change the name and i add [] to the end (for geting the value in PHP of all the checkboxes) javascript function stop works.. and don't check all the boxes, my script is like a MAIL so thats way i need all this checkboxes for DELETE options or others.. i have one checkbox that check or uncheck all the list <input type="checkbox" name="msgCheckCtrl" value="yes" onClick="msgSCheck();" />

Member Avatar for rajarajan2017
<input type="checkbox" name="msgCheckCtrl[]" value="yes" onClick="msgSCheck();" />

for that you need to do as bove within the name attribute. Thats all.

noo i don't need the value of that checkbox in php, that one is only for check or uncheck all the other!

like this one: <input type="checkbox" name="msgCList" value="93287" />
using the name msgCList works!!

but if i change it in to <input type="checkbox" name="msgCList[]" value="93287" />

and change in the fuction
function msgSCheck(){
// This ONE
chk = document.msgFList.msgCList[];
//---------------------------------
if(document.msgFList.msgCheckCtrl.checked==true){
for (i = 0; i < chk.length; i++)
chk.checked = true ;
}else{
for (i = 0; i < chk.length; i++)
chk.checked = false ;
}
}

i get errors... the name msgCList[] , the problem is [ and ] .

if nobody knows how to solve this lets try to make some changes in PHP,

how can i get the value of multiple checkbox with the same name?!
<input type="checkbox" name="msgCList" value="value1" />
<input type="checkbox" name="msgCList" value="value2" />

Member Avatar for rajarajan2017

I understand, then check your javascript function itself there in your php page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.