?
Solved

Javascript & PHP Array

Posted on 2004-03-30
2
Medium Priority
?
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
CosminB earned 450 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

777 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