Solved

Javascript & PHP Array

Posted on 2004-03-30
2
367 Views
Last Modified: 2008-03-17
ok guys,

i got this script,
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
            <script language=\"JavaScript\" type=\"text/javascript\">
            <!-- Begin
            var checkflag = \"false\";
            function check() {
                  if (checkflag == \"false\") {
                        for (i = 0; i < document.form2.movelist.length; i++) {
                              document.form2.movelist[i].checked = true;
                              alert(document.form2.movelist[i].value);
                        }
                        checkflag = \"true\";
                  }
                  else {
                        for (i = 0; i < document.form2.movelist.length; i++) {
                              document.form2.movelist[i].checked = false;
                        }
                        checkflag = \"false\";
                  }
            }
            -->
            </script>

<input type=checkbox name=movelist value=True>
<a href=\"#\" OnClick=\"check()\">Check all</a>

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

This script works fine, it CHECK & UNCHECK all the movelist checkbox without any problem.
But i need to set movelist to array, then only my php know which checkbox i've selected say out 10 checkbox, i've manually uncheck 3,
like this --> <input type=checkbox name=movelist[] value=True>
but if i were doing this, javascript throw me some error, HOW?

Thanks in advance!! :)
0
Comment
Question by:paulsiew
2 Comments
 
LVL 6

Accepted Solution

by:
CosminB earned 150 total points
Comment Utility
try this script(you'll have to adapt it to your needs):
----------------------------------------------------------------------------------
<html>
<head>
<script language="JavaScrip\" type="text/javascript">
      var checkflag = false;
      function check(){
            checkflag = (checkflag==true) ? false : true;
            for (i=0; i<document.forms['form2'].elements.length; i++)
            {
                  if (document.forms['form2'].elements[i].type == 'checkbox' && document.forms['form2'].elements[i].name == 'movielist[]')
                  {
                        document.forms['form2'].elements[i].checked = checkflag;
                  }
            }
      }
</script>
</head>
<body>
      <form action="" name="form2">
            <input type="checkbox" name="movielist[]" value="1" />
            <input type="checkbox" name="movielist[]" value="2" />
            <input type="checkbox" name="movielist[]" value="3" />
            <input type="checkbox" name="movielist[]" value="4" />
            <input type="checkbox" name="movielist[]" value="5" />
            <input type="button" onclick="check()" />
      </form>
</body>
</html>
----------------------------------------------------------------------------------
tested(and working) on  IE 5.0, Mozilla 1.3 and Firebird 0.7
0
 

Author Comment

by:paulsiew
Comment Utility
Thanks a lot, it works
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now