Results 1 to 10 of 10

Thread: [RESOLVED] Javascript Checkbox Problem...

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    47

    Resolved [RESOLVED] Javascript Checkbox Problem...

    PHP Code:
    <?
        include "Config.php";

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title></title>
    </head>

    <body>

    <script language='javascript'>
        function Cek01()
        {
            document.forms['FrmCheck'].ChkPil[0].checked=true;
        }
    </script>
    <Form name='FrmCheck' action='inp_MCU.php' method='POST'>
    <table width=800 border=1>

    <?
        $SQL="Select * From MCU_MSPackage order by CdCheck";
        $result=mysql_query($SQL);
        $tmpGroup="00";
        $ax=0;
        if (mysql_num_rows($result)>0)
        {
            while($row=mysql_fetch_array($result))
            {
                if($tmpGroup<>$row["CdGroup"])
                {
                    echo "<tr>";
                    echo "<td>"; 
                    ?>
                        <input type='checkbox' name='ChkGrp[]' onClick='Cek01();' /><input type='text' name='TxtABC' />
                    <?
                    echo"</td><td colspan=2>".$row["NmGroup"] . "</td>";
                    $tmpGroup=$row["CdGroup"];
                    echo "</tr>";
                }
    ?>
        <tr><td width=25></td>        
                <td><input  name='ChkPil[]' type='checkbox' value= <? echo $row["CdCheck"]; ?> /></td><td> <? echo $row["NmCheck"]."/".$row["NmEngland"];?></td>
        </tr>
    <?
            }
        }
    ?>
    <input type='submit' value='Send' />
    </table>
    </Form>
    </body>
    </html>
    Hello... I have some problem... with Javascript...
    I want if I Checked the "ChkGrp".. The Checkbox "ChkPil[0]" is checked...
    But I can't do it....
    Except i change name of "ChkPil[]" to "ChkPil". But I need array of Checkbox ... to next page...
    Any Solution...???
    Thanks...

  2. #2
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Javascript Checkbox Problem...

    pls explain more..what are you trying to do
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    47

    Re: Javascript Checkbox Problem...

    There is 2 type Checkbox...
    ChkGrp and ChkPil (Array of Checkbox) ....
    If I check "ChkGrp", I want ChkPil[0] was checked too... (only index 0 )...
    So I call function Cek01 on ChkGrp...
    But It doesn't work...EXCEPT if change name of "ChkPil[]" to "ChkPil"...
    But IF I CHANGE NAME to ChkPil.... when I send to other Page... with :
    $_POST["ChkPil"]; It's only return 1 value
    But with "ChkPil[]" when I send to other page , i can make array of this variable :
    $test=$_POST["ChkPil"];
    $text="";
    for($i=0;$i<sizeof($test);$i++)
    {
    $text = $text . $test[$i];
    }

    Just like that...

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Javascript Checkbox Problem...

    have you tried, using getElementByName or getElementById to access the element to change the value of it?

  5. #5
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Javascript Checkbox Problem...

    try saying this

    Code:
    document.forms['FrmCheck'].ChkPil+'[0]'.checked=true
    i had this problem in my code sometimes ago, thats what i did, and it did work fine..

    hope it helps
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    47

    Re: Javascript Checkbox Problem...

    Doesn't works... (
    if i'm using
    Code:
      alert("document.forms['FrmCheck'].ChkPil+'[0]'.checked);
    it will show alert "NaN";
    If i'm using Javascript Console on Firefox , it will show :
    "Invalid assignment left-hand side"...

  7. #7
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Javascript Checkbox Problem...

    that will be either outputing True or False

    and i don't think js will try to convert that to 0 or 1

    so i think that's why you get NaN(Not a Number)
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Javascript Checkbox Problem...

    I think it should be
    Code:
    alert(document.getElementByName('ChkPil[0]').checked);
    There should be no data type conversion happening. See what that returns.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Javascript Checkbox Problem...

    Also, if you want to get a form element:
    Code:
    document.forms[0].elements['ChkGrp[]'];
    If it is a list of checkboxes you'll get an array of elements.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    47

    Re: Javascript Checkbox Problem...

    Thank You...
    It's Works......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width