Jump to content

How to auto select a checkbox when List/Menu item is selected.


garymendi

Recommended Posts

Hi Guys,

I am new to php coding and I am trying to add some code that I wanted to work and what I want to supposed to happen. This code is about printing selected rows using check box. All the data that post from this form is coming from the database. What I want to do is to add a dropdown menu with the names of people (Pickupby) that will auto select the check box if one on the list from the dropdown menu is selected instead of ticking the checkbox manually. I will be very happy to those who have a  good heart that is willing to share their expertise on php to help me up solve my problem. Thank you and God Bless.

 

Below the script and some of it was taken from the web too.

 

 

<?php session_start(); ?><?php include('protect.php'); ?>
<!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>Untitled</title>
<script type="text/javascript">//<![CDATA[
// Shift-click Checkboxes
// By Jason Davis, jasonkarldavis@gmail.com
// You may freely distribute this script as long as these credits remain intact
function enhanceCheckboxes(parent) {
parent._shiftKey = false;
parent._lastCheck = null;

parent.addEventListener("click", function(event) {
parent._shiftKey = event.shiftKey;
}, false);

parent.addEventListener("change", function(event) {
var currentIndex, checkbox, start, end;

if (event.target.nodeName.toUpperCase() == "LABEL") {
if (event.target.hasAttribute("for"))
checkbox = document.getElementById(event.target.getAttribute("for")) ||
document.getElementsByName(event.target.getAttribute("for")).item(0);
else
checkbox = event.target.getElementsByTagName("input").item(0);
}
else
checkbox = event.target;

if (parent._shiftKey && parent._lastCheck != null) {
for (var i = 0; i < checkbox.form.elements.length; i++) {
if (checkbox.form.elements == checkbox) {
start = checkbox;
end = parent._lastCheck;
currentIndex = i;
break;
}
else if (checkbox.form.elements == parent._lastCheck) {
start = parent._lastCheck;
end = checkbox;
currentIndex = i;
break;
}
}

for (currentIndex += 1; currentIndex < checkbox.form.elements.length && checkbox.form.elements[currentIndex] != end; currentIndex++) {
if (checkbox.form.elements[currentIndex].type == "checkbox") {
checkbox.form.elements[currentIndex].checked = true;
}
}

parent._lastCheck = end;
}
else
parent._lastCheck = checkbox;

parent._shiftKey = false;
}, false);
}

window.onload = function() {
enhanceCheckboxes(document.getElementsByTagName("form")[0]);
}
//]]></script>
<style type="text/css">
<!--

body {
 margin-top: 5px;
 margin-right: 0px;
 margin-bottom: 0px;
 margin-left: 0px;
 padding-top: 5px;
 padding-right: 0px;
 padding-bottom: 0px;
 padding-left: 0px;
}
.fc_title {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 font-weight: bold;
 color: #000000;
 padding-left: 7px;
 padding-right: 7px;
 border-bottom-width: 4px;
 border-bottom-style: solid;
 border-bottom-color: #999999;
 text-transform: uppercase;
}

.fc_schedule_text {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 font-weight: normal;
 color: #000000;
 padding-left: 7px;
 padding-right: 7px;
 border-bottom-width: 1px;
 border-bottom-style: solid;
 border-bottom-color: #999999;
 height: 26px;
 padding-top: 9px;
 padding-bottom: 2px;
 text-transform: uppercase;
}
.fc_maintitle {
 font-family: Arial, Helvetica, sans-serif;
 font-size: 18px;
 font-weight: normal;
 color: #000000;
 padding-left: 24px;
}
a:link {
 font-size: 14px;
 font-weight: normal;
 color: #000000;
 text-decoration: underline;
}
a:active {
 font-size: 14px;
 font-weight: normal;
 color: #000000;
 text-decoration: underline;
}
a:visited {
 font-size: 14px;
 font-weight: normal;
 color: #000000;
 text-decoration: underline;
}
a:hover {
 font-size: 14px;
 font-weight: normal;
 color: #000000;
 text-decoration: underline;
}
 
-->
</style>
<style type="text/css">
<!--
@media print {
  .DONTPrint{ display:none }
  .DOCheck{ display:table}
  #ad{ display:none;}
}
-->
</style>
<script type="text/javascript">
<!--
/* This script and many more are available free online at
The JavaScript Source :: http://www.javascriptsource.com
Created by: Thony den Braber :: http://www.orangespirits.nl */

function select_row(row, color) {
  if(row.parentNode.parentNode.style.backgroundColor != color) {
    row.parentNode.parentNode.style.backgroundColor = color;
    row.parentNode.parentNode.className = 'DOPrint'
  } else {
  row.parentNode.parentNode.style.backgroundColor = '';
  row.parentNode.parentNode.className = 'DONTprint'
  }
}

function mouseover(row, font_color, checkedcolor) {
  if(row.style.color != checkedcolor) {
    row.style.color = font_color;
  }
}

function mouseout(row, font_color, checkedcolor) {
  if(row.style.color != checkedcolor) {
    row.style.color = font_color;
  }
}
// -->
</script>
<link href="print.css" rel="stylesheet" type="text/css" media="print" />
</head>

<body>

<div align="center" class="fc_maintitle">SCHEDULED PICK UP
<div align="center" id="ad"><a href="javascript:window.print()"><img src="print.gif" width="18" height="18" border="0" /></a> <input type=image src="fc_close.png" value="Close Window" onClick="javascript:window.close();"> </div>
  <table width="98%" align="center" cellpadding="0" cellspacing="0" >
          <!--DWLayoutTable-->
<tr>
      <td width="4%" height="36" valign="middle" class="fc_title" ><div align="left">SELECT</div></td>
      <td width="7%" valign="middle" class="fc_title" ><div align="left">Agent name</div></td>
      <td width="7%" height="36" valign="middle" class="fc_title"><div align="left" >PICKUP Date</div></td>
      <td width="7%" height="36" valign="middle" class="fc_title"><div align="left" >PICKUP Time</div></td>
      <td width="14%" height="36" valign="middle" class="fc_title"><div align="left">Customer Name</div></td>
      <td width="21%" height="36" valign="middle" class="fc_title"><div align="left" >customer Address</div></td>
      <td width="7%" height="36" valign="middle" class="fc_title"><div align="left"  >Postal code</div></td>
      <td width="7%" height="36" valign="middle" class="fc_title"><div align="left" >Phone no.</div></td>
      <td width="4%" height="36" valign="middle" class="fc_title"><div align="left" >Boxes</div></td>
      <td width="5%" height="36" valign="middle" class="fc_title"><div align="left" >Amount</div></td>
      <td width="17%" height="36" valign="middle" class="fc_title"><div align="left" >comments / instructions</div></td>
    </tr>
  </table>

<?
 
include("../dbconnect.php");
$strid=$_POST['track'];
$strid1=$_GET['id'];
 
$query=mysql_query("select * from cargo2 WHERE Pickupdate = '$strid' <> 'DELIVERED' order by Pickupdate desc ");
if($alert=mysql_num_rows($query) == 0)
{
?>
      <? echo "No Records Found" ; ?>
      <? } else {
 
$sql = mysql_query("SELECT * FROM cargo1 where Pickupdate = '$strid' <> 'DELIVERED' order by Pickupdate desc ");
 
while($row = mysql_fetch_array($sql))
{ ?>
<form>
<label>
  <table width="98%" align="center" cellpadding="0" cellspacing="0" >
          <!--DWLayoutTable-->
   
<tr onMouseOver="mouseover(this,'#cc6600','#cc6600');" onMouseOut="mouseout(this,'#000000','#000000')" class='DONTPrint'>
  <td width="4%" height="26" valign="middle" ><input type="checkbox" name="checkbox" onClick="select_row(this, '#E6F3FF');"></td>
  <td width="7%" valign="middle" ><div align="left" class="fc_schedule_text"><? echo $row["Pickupby"];?></div></td>
  <td width="7%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Pickupdate"];?></div></td>
  <td width="7%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Pickuptime"];?></div></td>
  <td width="14%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Sendername"];?></div></td>
  <td width="21%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Senderaddress"];?></div></td>
  <td width="7%" height="26" valign="middle"><div align="left" class="fc_schedule_text" ><? echo $row["Senderpostalcode"];?></div></td>
  <td width="7%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Senderphone"];?></div></td>
  <td width="4%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Totalboxes"];?></div></td>
  <td width="5%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Sales"];?></div></td>
  <td width="17%" height="26" valign="middle"><div align="left" class="fc_schedule_text"><? echo $row["Comments"];?></div></td>
</tr>
  </table>
  </label>
  </form>
<?php
    $strfilter = $row["Status"];
    if ($strfilter == "DELIVERED")
    {
    
    ?>
        <? }
    else
    {
    }
    ?>
        <? 
          }
   
   ?>
        <?
  $strid = $_POST['track'];
  $result1 = mysql_query("SELECT *,TIMEDIFF(time, '6:00' ) AS mountaintime FROM upstatus WHERE hwid = '$strid' or hwid = '$strid1'");
?>
        <?  while($row = mysql_fetch_array($result1))
  { ?>
        <? }?>
        <? } ?>
</div>
</body>
</html>

Edited by garymendi
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.