Solved

Javascript & PHP Array

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
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 …

717 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