-1

i have few checkboxes named as HR,visitor,gaurd now i want to get which ever chckbox is selected according to it names of the employee belonging to that team whether HR or Guard or visitor to be shown in dropdown list

<select name=cmbname id="cmbname" width='50%'>

ALL

`

    $objDB->SetQuery($sql);

    $res = $objDB->GetQueryReference();

    if(!$res)
        exit("Error in SQL : $sql");

    if($objDB->GetNumRows($res) > 0)
    {
        while($row = mysql_fetch_row($res))
        {

                print("
            <option value='{$row[0]}'>{$row[0]}</option>");

        }
    }
    mysql_free_result($res);

?>'

Lissa
  • 23
  • 4
  • show the appropriate code please. –  Jul 17 '12 at 09:41
  • what you are tried?? please show it – Jalpesh Patel Jul 17 '12 at 09:41
  • lol, first answer always seems to be jQuery related – Jon Taylor Jul 17 '12 at 09:41
  • 2
    paste some code which you tried.... – Jithin Jul 17 '12 at 09:41
  • @JonTaylor because this solution is best accomplished with jQuery. – Peon Jul 17 '12 at 09:44
  • @DainisAbols no, it may be simpler, it is not necesserily best accomplished with it. It is a trivial task in standard javascript without the use of jQuery. Using jQuery libraries unfortunately seems to be the first answer to every javascript question on SO, people are starting to forget how to actually use standard javascript which means when jQuery can't solve their problem they sit there thinking the world has coem to an end. (Something I see quite often unfortunately). – Jon Taylor Jul 17 '12 at 09:47
  • new to php n javascript so want to know the code to strat with – Lissa Jul 17 '12 at 09:54
  • i have desinged the HTML page now just want to know how to get values in the option tag – Lissa Jul 17 '12 at 09:55

2 Answers2

0

Himani ,

Try this. Hope it will be useful to you. Instead of text-area you can use drop-down.

Community
  • 1
  • 1
iLaYa ツ
  • 3,941
  • 3
  • 32
  • 48
0

Try this way gives you solution

 <script type="text/javascript">
 //javascript 
 function clicked_checkbox()
 {  
   document.form.submit();  
 }
 </script>
 <?php
 $hr = isset($_REQUEST['HR'])?$_REQUEST['HR']:false;
 $guest = isset($_REQUEST['guest'])?$_REQUEST['guest']:false;
 $visiter = isset($_REQUEST['visiter'])?$_REQUEST['visiter']:false;

//Prepare query with retrieved value and put value in Dropdown
$sql = 'select * from table ';
if($hr)      { $sql .= "where user = '$hr'" };
if($guest)   { $sql .= "where user = '$guest'" };
if($visiter) { $sql .= "where user = '$hr'" };

$objDB->SetQuery($sql);
$res = $objDB->GetQueryReference();

if(!$res)
    exit("Error in SQL : $sql");

if($objDB->GetNumRows($res) > 0)
{
    while($row = mysql_fetch_row($res))
    {
        print("<option value='{$row[0]}'>{$row[0]}</option>");
    }
}
mysql_free_result($res);
?>

//on change of checkbox we'll call above function and set data to dropdown
<form name='form' method='get' action='#'>
<input type="checkbox" id="checkbox_HR" name="HR" value="true" <?php if($hr) echo "checked='checked'"; ?> onchange="return clicked_checkbox();">
 <input type="checkbox" id="checkbox_guest" name="guest" value="true" <?php if($guest) echo "checked='checked'"; ?> onchange="return clicked_checkbox();">
  <input type="checkbox" id="checkbox_user" name="visiter" value="true" <?php  if($visiter) echo "checked='checked'"; ?> onchange="return clicked_checkbox();">
 </form>

like this you can achieve :)

Zuber Surya
  • 839
  • 7
  • 17