Rotary button with drop down list

I am looking for a page 1 button and 1 drop down list with following functionality.

Button label should change in rotary manner on clicking (Enginerring, Sales, Accounting, HR ......... then again ... Engineering)
When button has "Engineering" label ,drop down list should display (Developer, QA, Manager) menu items
When button has "Sales" label, drop down list should display (Sales Executive, Sales Manager, Sales Man) menu items
When button has "Accounting" label, drop down list should display (CFO, Accountant, Clerk) menu items
When button has "HR" label, drop down list should display (Manager, Recruiter) menu items
I do not want to use to separate drop down list for Department and Position.

I am using PHP. Please give me PHP code.
Is there any better way to do it besides using Rotary button and a list?
Please suggest me both options.
Thanks,

 
patilarvindgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

scrathcyboyCommented:
You cannot get this style of interface choice to work in PHP.  PhP is a server language that delivers a static page to the browser.  Yes, the PHP can embed javascript in the page to rotate the button, and thence pull down additional javascript functions to change the drop down list ... but that is clumsy.

Since what you are requiring or asking is an interactive page at the user level, you should do it all in javascript, and not PHP.  The final form can submit to a PHP page on the server, that is fine, but all the user interaction is at the browser level, and that is best done in javascript.

If you want to use PHP for this, you would need one dropdown liist to replace your button rotation and then depending on the choice of that drop down list, you would change the choices in the other drop down list.  However, I have done this on several websites, and it is STILL better done in javascript than PHP.  Keep the PHP for submitting the user choices to the server, and process them there.
0
darron_chapmanCommented:
Something like this?
<?php
$button=$_POST['button'];
if (isset($_POST['button']))
{
  if ($button=="Engineering")
  {
    $curDept="Sales";
	$curPosArray= array("Sales Executive", "Sales Manager", "Sales Man");
  }
  elseif ($button=="Sales")
  {
    $curDept="Accounting";
	$curPosArray= array("CFO", "Accountant", "Clerk");
  }
  elseif ($button=="Accounting")
  {
    $curDept="HR";
	$curPosArray= array("Manager", "Recruiter");
  }
  elseif ($button=="HR")
  {
    $curDept="Engineering";
	$curPosArray= array("Developer", "QA", "Manager");
  }
}
else  {
$curDept="Engineering";
$curPosArray= array("Developer", "QA", "Manager");
}
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='submit' value='".$curDept."' name='button'>";
echo "<select name='position'>";
foreach($curPosArray as $position)
{
echo "<option value='".$position."'>".$position."</option>";
}
echo "</select>";
echo "</form>"
 
?>

Open in new window

0
Ali KayahanFull Stack DeveloperCommented:
         It seems that darron_chapman wrote the code in the way that you want ,but as scrathcyboy said its not the way to do it.The thing that you want is a client side operation and using php for client side isnt a good way,because refreshing page everytime whenever user clicks the button should be annoying. In client side scripting using javascript would be the best and the fastest  solution,and than sure you will grab the information with php when form submitted.
           Just copy and paste the code below ,get the filter.txt file and rename it as filter.js and keep 2 files in the same folder.
         
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1254">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-9">
<meta http-equiv="content-language" content="EN">
<META content="MSHTML 6.00.2900.3059" name=GENERATOR>
<link rel="stylesheet" href="../css/ogretmen.css" type="text/css" media="screen" />
<script src="filter.js"></script>
<script language="JavaScript">
auto_enable_disable = true;
</script>
<form action="myphp_file.php" method="post">
<select name="department" onchange="filterSelect(subcategory,this)" >
<option value="" filter="">--Choose Department--</option>
              <option value="engineering" filter="engineering">Engineering</option>
              <option value="sales" filter="sales">Sales</option>
              <option value="Accounting" filter="Accounting">Accounting</option>
              <option value="HR" filter="HR">HR</option>
</select>
<select name="subcategory" onchange="filterSelect(subcategory,this)" disabled="true">
<option value="" filter="">--Choose Subcategory--</option>
              <option value="developer" filter="engineering">Developer</option>
               <option value="QA" filter="engineering">QA</option>
               <option value="manager" filter="engineering">Manager</option>
              <option value="SalesExecutive" filter="sales">Sales Executive</option>
              <option value="SalesMan" filter="sales">Sales Man</option>
              <option value="SalesManager" filter="sales">Sales Manager</option>
              <option value="CFO" filter="Accounting">CFO</option>
              <option value="Accountant" filter="Accounting">Accountant</option>
              <option value="Clerk" filter="Accounting">Clerk</option>
              <option value="Manager" filter="HR">Manager</option>
              <option value="Recruiter" filter="HR">Recruiter</option>
</select>
<input type="submit" value="Go On">
</form>

filter.txt
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

darron_chapmanCommented:
2 things the asker asked for:
>I do not want to use to separate drop down list for Department and Position

and
>I am using PHP. Please give me PHP code.

I have provided both:
Here is a little better code that gives you another form with your drop down list.  Please note that you embed the drop down list-

echo "<select name='position'>";
foreach($curPosArray as $position)
{
echo "<option value='".$position."'>".$position."</option>";
}
echo "</select>";

-into any form on your page


<?php
$button=$_POST['button'];
if (isset($_POST['button']))
{
  if ($button=="Engineering")
  {
    $curDept="Sales";
	$curPosArray= array("Sales Executive", "Sales Manager", "Sales Man");
  }
  elseif ($button=="Sales")
  {
    $curDept="Accounting";
	$curPosArray= array("CFO", "Accountant", "Clerk");
  }
  elseif ($button=="Accounting")
  {
    $curDept="HR";
	$curPosArray= array("Manager", "Recruiter");
  }
  elseif ($button=="HR")
  {
    $curDept="Engineering";
	$curPosArray= array("Developer", "QA", "Manager");
  }
}
else  {
$curDept="Engineering";
$curPosArray= array("Developer", "QA", "Manager");
}
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='submit' value='".$curDept."' name='button'/>";
echo "</form>";
echo "<form method='post' action='anotherpage.php'>";
echo "<select name='position'>";
foreach($curPosArray as $position)
{
echo "<option value='".$position."'>".$position."</option>";
}
echo "</select>";
echo "<input type='submit'/ value='Submit'>";
echo "</form>";
 
?>

Open in new window

0
Ali KayahanFull Stack DeveloperCommented:
So we can read and understand as well as you :),do not worry about the points because as i mentioned above you gave the code that the asker asks for...
But the thing that he asks for is not the true way of the thing that he tries to do,i just remind this and show the true form of it.
0
scrathcyboyCommented:
I still maintain that you cannot do a rotary button with PHP, it is ridiculous to do a page refresh every time the button rotates.  You HAVE to send client side javascript to the browser, that is the only realistic way to do it, so whether you devise a PHP to send that Javascript (inefficient) or just put it in the file to begin with (efficient) it is just an issue of semantics.  I'll leave this Q now and see if that realization eventually takes.
0
darron_chapmanCommented:
:-) ... sorry, meant no disrespect
0
patilarvindgAuthor Commented:
Thanks to ali_kayahan, scrathcyboy and  darron_chapman for their comment and solutions.

But since this particular selection (department-position combination) will be mostly selected once by one user.
One user will be using one particular combination all the time.
Still want to give easy interface to make change in their combination by individual user.

So in this case I like darron_chapman's solution more than the other one.

Darron,
How do I change this script to have one check box with the combination which should allow user to lock their selection even on page reload. (disable button and a list when check box is checked and keep existing selection)

Thanks.
0
darron_chapmanCommented:
This can be accomplished using cookies and a save check box.  See below
<?php
$button=$_POST['button'];
 
if (isset($_COOKIE['curDept']))
{
  $curDept=$_COOKIE['curDept'];
  $position=$_COOKIE['position'];
}
 
if ($_POST['Save']=="on")
{
  setcookie(curDept,$_POST['curDept'],time()+60*60*24*30);
  setcookie(position,$_POST['position'],time()+60*60*24*30);
  $curDept=$_POST['curDept'];
  $position=$_POST['position'];
}
 
 
 
if (isset($button))
{
  if ($button=="Engineering")
  {
    $curDept="Sales";
	$curPosArray= array("Sales Executive", "Sales Manager", "Sales Man");
  }
  elseif ($button=="Sales")
  {
    $curDept="Accounting";
	$curPosArray= array("CFO", "Accountant", "Clerk");
  }
  elseif ($button=="Accounting")
  {
    $curDept="HR";
	$curPosArray= array("Manager", "Recruiter");
  }
  elseif ($button=="HR")
  {
    $curDept="Engineering";
	$curPosArray= array("Developer", "QA", "Manager");
  }
}
elseif (!isset($curDept))  {
$curDept="Engineering";
$curPosArray= array("Developer", "QA", "Manager");
}
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='submit' value='".$curDept."' name='button'/>";
if (isset($curPosArray))
{
  echo "<select name='position'>";
  foreach($curPosArray as $position)
  {
    echo "<option value='".$position."'>".$position."</option>";
  }
  echo "</select>";
}
else echo $position;
echo "<input type='checkbox' name='Save'> Save<br>";
echo "<input type='hidden' name='curDept' value='$curDept'/>";
echo "<input type='submit' name='submit' value='Submit'/>";
echo "</form>";
 
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
patilarvindgAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.