Solved

Javascript & PHP Array

Posted on 2004-03-30
2
368 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
ID: 10712598
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
ID: 10720421
Thanks a lot, it works
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

19 Experts available now in Live!

Get 1:1 Help Now