Welcome Guest, Not a member yet? Register   Sign In
Javascript and "check all" condition in View...
#1

[eluser]bianchi[/eluser]
Hello friends,

I wanna have a "check all" check box in my form,
but when it's an array the javascript won't work,

Any of you ever hv a same situation,
Please share with me...
I will be gratefull for every response,
I can't use
"onClick="UnCheckAll(document.airline_form.airline[])">"--->not working...

Regards,
CI Developer...
================
<html>
<head>
[removed]
<!--

<!-- Begin
function CheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}

function UnCheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
// End --&gt;
[removed]
&lt;/head&gt;
&lt;body&gt;

<br>
&lt;form name="airline_form" action="checkbox/delete" method="post"&gt;
&lt;input type="button" name="Check_All" value="Check All"&gt;
&lt;input type="button" name="Un_CheckAll" value="Uncheck All"&gt;
&lt;input type="submit" value="DELETE" class="button"/&gt;
<br>

&lt;? //foreach($query as $row){ echo "<option value='$row->code2'>$row->name</option>";}
foreach($query as $row){ echo "&lt;input type='checkbox' name='airline[]' value='$row-&gt;code2'>$row->name<br>";}?&gt;
&lt;input type="submit" value="DELETE" class="button"/&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]icomefromthenet[/eluser]
here is a javascript function I use from time to time to have a check all function

Code:
function checkAll(){
    for (var i=0;i<document.forms[0].elements.length;i++)
      {
        var e=document.forms[0].elements[i];
        if ((e.name != 'allbox') && (e.type=='checkbox'))
        {
            e.checked=document.forms[0].allbox.checked;
        }
    }
}

need to change this line to match your form
Code:
(e.name != 'allbox')
#3

[eluser]bianchi[/eluser]
[quote author="icomefromthenet" date="1269416910"]here is a javascript function I use from time to time to have a check all function

Code:
function checkAll(){
    for (var i=0;i<document.forms[0].elements.length;i++)
      {
        var e=document.forms[0].elements[i];
        if ((e.name != 'allbox') && (e.type=='checkbox'))
        {
            e.checked=document.forms[0].allbox.checked;
        }
    }
}

need to change this line to match your form
Code:
(e.name != 'allbox')
[/quote]

I'll try...tx




Theme © iAndrew 2016 - Forum software by © MyBB