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
Solved

Javascript & PHP Array

Posted on 2004-03-30
2
370 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I make this form submit to itself? 10 35
two ways encryption with php 3 37
php56-php-mcrypt for rhel7 php56 1 50
Why will this INSERT statement not insert the date? 2 20
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 …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to dynamically set the form action using jQuery.
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…

856 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