Jump to content

Get Arrays and checkbox checked when returning url


Rodis

Recommended Posts

Hello,

 

Hope someone can help me cause i been at it all day and google woul'dn't help me.

 

I been writing a little script which generates a list of numbers you can check and make a list of the numbers that have been checked. Now when i use $_get to the next page everything works but now i need to take the url and use $_get back to the generated check box list and it needs to know by the url which box had been checked and checked that one so the list can be altered. here is my code sofar

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AH plaatjes.</title>
</head>

<body name="top">
Meer info beneden aan de pagina. <a href="#beneden">Naar beneden.</a>
<p>
  <script language=JavaScript>
function set(n) 
{
temp = document.form1.elements.length ;
for (i=0; i < temp; i++)
{ document.form1.elements[i].checked=n;
}
} 

function checkall()
{
void(d=document);
void(el=d.getElementsByName('check'));
for(i=0;i<el.length;i++)
void(el[i].checked=1) 
}

//invert
function invers(){
temp = document.form1.elements.length ;
for (i=0; i < temp; i++){
if(document.form1.elements[i].checked == 1){document.form1.elements[i].checked = 0;}
else {document.form1.elements[i].checked = 1}
}
}


</script> 
</p>
<form id="form1" name="form1" method="get" action="./readlist.php">
<label>Naam eigenaar lijstje:<input name="naam" type="text" /></label>
<label>Lijst van selectie plaatjes<select name="collect">
  <option value="0">selecteer optie!</option>
  <option value="1">in decollectie</option>
  <option value="2">nog niet in collectie</option>
  <option value="3">dubbele collectie</option>
</select></label>
  <p>
  <?php
  //TO Do trying to get the checkboxes checked with get and array

  
  /////////////////

  do {
  $i = $i+1;
  echo "
      <input type=\"checkbox\" name=\"checked[]\" id=\"check\" value=\"". $i ."\"/>
      <label for=\"". $i ."\">". $i ."</label>
      <br />
";
if($i > 324){break;}
  }// end do
  while($i < 325);
?>
    
  </p><input name="check" type="submit" value="Print lijst" />
  <input type=button onClick="checkall()" value="selecteer alles" name="button"> 
  <input name=button onclick="invers()" type=button value=" Keer selectie om ">
      <INPUT name=button onclick=set(0) type=button value=" Reset ">  

</form>
<p><a name="beneden">De geselecteerde nummers komen overzichtelijk in een lijstje. Zo heb je heel overzichtelijk een lijst met de nummers die je al hebt of juist nog niet hebt. Die kan je dan doorsturen selecteren en kopieren met je rechtermuis knop en naar je kennissen of vrienden sturen.</a> ook kan je de url (webadres) kopieren en doorgeven.</p>
<p><a href="#top">Naar boven.</a></p>
</body>
</html>




Now what i need is when you fill out an url like http://localhost/ah/index.php?checked%5B%5D=2&checked%5B%5D=3 it needs to check the same boxes. please help me out thanks in advance

Link to comment
Share on other sites

I'm not sure I totally understand, but something like this maybe:

 

for($i=0; i$<325; $i++) {
   $checked = in_array($i, $_GET['checked']) ? 'checked' : '';
   echo "<input $checked type=\"checkbox\" name=\"checked[]\" id=\"check\" value=\"". $i ."\"/>";
}

 

Or alternately, depends on what you need (same thing really):

 

for($i=0; i$<325; $i++) {
   $checked = isset($_GET['checked'][$i]) ? 'checked' : '';
   echo "<input $checked type=\"checkbox\" name=\"checked[$i]\" id=\"check\" value=\"". $i ."\"/>";
}

Link to comment
Share on other sites

Damn you're the bomb this works and this is my code now.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
//  End -->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AH voetbal plaatjes lijst.</title>
<style type="text/css">
<!--
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
background: #4E5869;
margin: 0;
padding: 0;
color: #000;
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
padding-right: 15px;
padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
border: none;
}

/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
color:#414958;
text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
color: #4E5869;
text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
text-decoration: none;
}

/* ~~ this container surrounds all other divs giving them their percentage-based width ~~ */
.container {
width: 100%;
max-width: 1260px;/* a max-width may be desirable to keep this layout from getting too wide on a large monitor. This keeps line length more readable. IE6 does not respect this declaration. */
min-width: 780px;/* a min-width may be desirable to keep this layout from getting too narrow. This keeps line length more readable in the side columns. IE6 does not respect this declaration. */
background: #FFF;
margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout. It is not needed if you set the .container's width to 100%. */
}

/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
background: #6F7D94;
height:90px;
color:#FFF;
}


.sidebar1 {
float: right;
width: 20%;
background: #93A5C4;
padding-bottom: 10px;
}
.content {
padding: 10px 0;
width: 80%;
float: right;
}

/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol { 
padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
}

/* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */
ul.nav {
list-style: none; /* this removes the list marker */
border-top: 1px solid #666; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
ul.nav li {
border-bottom: 1px solid #666; /* this creates the button separation */
}
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
padding: 5px 5px 5px 15px;
display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
text-decoration: none;
background: #8090AB;
color: #000;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
background: #6F7D94;
color: #FFF;
}

/* ~~ The footer ~~ */
.footer {
padding: 10px 0;
background: #6F7D94;
position: relative;/* this gives IE6 hasLayout to properly clear */
clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
.container .footer p {
color: #FFF;
text-align: center;
font-size:10px;
}
-->
</style><!--[if lte IE 7]>
<style>
.content { margin-right: -1px; } /* this 1px negative margin can be placed on any of the columns in this layout with the same corrective effect. */
ul.nav a { zoom: 1; }  /* the zoom property gives IE the hasLayout trigger it needs to correct extra whiltespace between the links */
</style>
<![endif]--></head>

<body name="top">

<div class="container">
  <div class="header">
  <img src="./images/voetbalkaartje.png" alt="" name="Insert_logo" width="86" height="100" id="Insert_logo" style="background: #8090AB; display:block; float:left; margin-left:20px;" />
<h1>Mijn lijstje van AH voetbal plaatjes!</h1>
    <!-- end .header --></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="makelist.php">Nieuw lijstje maken.</a></li>
      <li><a href="index.php">Naar de gebruiksaanwijzing.</a></li>
      <li><a href="http://tinyurl.com/" target="_blank">Naar TinyURL gaan.</a></li>
    </ul>
    <p> Mijn Ah lijstje is een service van <a href="http://www.startbasis.nl">Starbasis.nl</a></p>
    <!-- end .sidebar1 --></div>
  <div class="content">
<p align="center">
Meer info beneden aan de pagina. <a href="#beneden"> Naar beneden.</a>
</p>
<p>
  <script language=JavaScript>
function set(n) 
{
temp = document.form1.elements.length ;
for (i=0; i < temp; i++)
{ document.form1.elements[i].checked=n;
}
} 

function checkall()
{
void(d=document);
void(el=d.getElementsByName('check'));
for(i=0;i<el.length;i++)
void(el[i].checked=1) 
}

//invert
function invers(){
temp = document.form1.elements.length ;
for (i=0; i < temp; i++){
if(document.form1.elements[i].checked == 1){document.form1.elements[i].checked = 0;}
else {document.form1.elements[i].checked = 1}
}
}


</script> 
</p>
<?php 
if (!empty($_GET['naam'])){
$naam = "value=\"".$_GET['naam']."\"";
} else {
$naam = "";
}
// selected by collect=0,1,2,3 Using $_GET
?>
<form id="form1" name="form1" method="get" action="./readlist.php">
<label>Naam eigenaar lijstje:<input name="naam" type="text" <?php echo $naam ;?>/></label>
<label>Lijst van selectie plaatjes:<select name="collect">
  <option value="0">selecteer optie!</option>
  <option value="1">in decollectie</option>
  <option value="2">nog niet in collectie</option>
  <option value="3">dubbele collectie</option>
</select></label>
  <p>
  <?php
  //new code
  if (!empty($_GET['checked'])){
	  for($i=0; $i<326; $i++) {   
	  $checked = in_array($i, $_GET['checked']) ? 'checked' : '';
	  echo "
	  <input $checked type=\"checkbox\" name=\"checked[]\" id=\"check\" value=\"". $i ."\"/>
	  <label for=\"". $i ."\">". $i ."</label>
	  <br />
	  ";
	  }
  }//end new code
echo "tussen 2 codes in"; 	
  if (empty($_GET['checked'])){
  $i = 0;
  	do {
	  $i = $i+1;
	  echo "
     		<input type=\"checkbox\" name=\"checked[]\" id=\"check\" value=\"". $i ."\"/>
      		<label for=\"". $i ."\">". $i ."</label>
     	 	<br />
	";
	if($i > 324){break;}
	}// end do
  while($i < 325);
  }
?>
    
  </p><input name="check" type="submit" value="Print lijst" />
  <input type=button onClick="checkall()" value="selecteer alles" name="button"> 
  <input name=button onclick="invers()" type=button value=" Keer selectie om ">
      <INPUT name=button onclick=set(0) type=button value=" Reset ">  

</form>
<p><a name="beneden">De geselecteerde nummers komen overzichtelijk in een lijstje. Zo heb je heel overzichtelijk een lijst met de nummers die je al hebt of juist nog niet hebt. Die kan je dan doorsturen selecteren en kopieren met je rechtermuis knop en naar je kennissen of vrienden sturen.</a> ook kan je de url (webadres) kopieren en doorgeven.</p>
<p><a href="#top">Naar boven.</a></p>
</p>
    
    <!-- end .content --></div>
  <div class="footer">
    <p>Copyright by <a href="http://www.startbasis.nl">Startbasis.nl</a></p>
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
</html>

Thanks a million.

 

Now all i have to do is solve this in the option 2 but that shouldn't be to hard

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.