0

I just want to do something when an option is clicked on/set before submitting its containing form.

Here is my code

echo "  <form  method='post' action='employees.php?go'  id='searchform' >";
echo "<tr>","<td>","<select  name='inpuQuery'  style ='width:200px;border-radius: 25px;'>",
      "<option value='-1'>Filter:</option>",
      "<option value='Name'>Name</option>",
      "<option value='Surname'>Surname</option>",
      "<option value='ID_No'>ID_No</option>",
   "</select >",
 "<td>", "<tr>";

echo "<tr>","<td>"," <input style='border-radius: 25px;color:blue;width:200px;' type='submit'  name='filter' value='Search'> ","<td>", "</tr>";

//the if statement for if isset the search submit query
if(isset($_POST['filter'])){
    $criteria=$_POST['inpuQuery'];
    switch ( $criteria) {
    case "Name":
              echo "<input  type='text' style ='border-radius: 25px;width:200px;height:40px;'  placeholder ='enter first name to search by' name='name_query' > ";
               break;
    case "Surname":
               echo "<input   type='text'  style ='border-radius: 25px;width:200px;height:40px;'  placeholder='enter surname to search by' name='surname_query' > ";   
               break; 
    case "ID_No":
                echo "<input  type='text' style ='border-radius: 25px;width:200px;height:40px;'  placeholder ='enter ID Num to search by' name='id_query' > ";
            break; 
    } 
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • well you need to do it with javascript, and you have no tag of javascript... you can't do it with php. I've added a javascript tag for you – monxas Jul 30 '15 at 14:48
  • @monxas , thanx for your suggestion, any proposal on how I can accomplish it with javascript? – Tichaona Masanga Jul 30 '15 at 14:51
  • What do you wanna do? If you need to check something from DB or so you need to look into Ajax, Javascript. Make a separate php page and call it to check whatever you wanna check.. – Serhat Akay Jul 30 '15 at 14:53
  • don't put **"hi guys"** in the post subject and try to make it very concise – Abdo Adel Jul 30 '15 at 14:53
  • @SerhatAkay Im not checking anything from the database, I just want to determine whether the html option of the a selection has been clicked on – Tichaona Masanga Jul 30 '15 at 14:56
  • It is commonly done. You can do a search. Here is the one I found for you: http://stackoverflow.com/questions/24750766/calling-javascript-function-from-a-select-onchange – Serhat Akay Jul 30 '15 at 14:57
  • @SerhatAkay thanx a lot I will implement that . – Tichaona Masanga Jul 30 '15 at 15:00

0 Answers0