title: How to add select box field dynamically after clicking add button by using php or javascript and store selected value in selected box in database
body: <pre><code>if (isset($_POST['dept']) &amp;&amp; isset($_POST['batch']) &amp;&amp; isset($_POST['Month']) &amp;&amp; isset($_POST['Year']) &amp;&amp; isset($_POST['semester']))   // based on these values selected from database 
  {
  $dept = $_POST['dept'];
  $batch = $_POST['batch'];
   $month = $_POST['Month'];
  $year = $_POST['Year'];
   $semester = $_POST['semester'];
  
  $query = db_select('student_master');
  $query-&gt;fields('student_master', array('reg_no','name','dob','dept_code','degree','batch_year'));
  $query-&gt;condition('dept_code',$dept,'=') AND $query-&gt;condition('batch_year',$batch,'=');
  $results = $query-&gt;execute();
  
  echo "&lt;table&gt;";
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;label for='reg_no'&gt; Registration Number &lt;/label&gt;&lt;/td&gt;";
  echo "&lt;td&gt;";
  echo "&lt;select name='reg_no'&gt;";
  
  foreach($results as $student_result)
  { 
  echo "&lt;option value ='$student_result-&gt;reg_no'&gt; $student_result-&gt;reg_no&lt;/option&gt;";
  } 
  
  echo "&lt;/select&gt;";
  echo "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  
  $query = db_select('subject');
  $query-&gt;fields('subject', array('subject_name','credits','subject_code'));
  $query-&gt;condition('dept_code',$dept,'=') AND $query-&gt;condition('semester_appear',$semester,'=') ;
  $subject_results = $query-&gt;execute();
  
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;label for='Subject'&gt;Subject Name&lt;/label&gt;&lt;/td&gt;";  
  echo "&lt;td&gt;";
  echo "&lt;select name = 'sub_name' id = 'sub_name'&gt;";
  
  foreach($subject_results as $subjects_result)
  { 
  echo "&lt;option value ='$subjects_result-&gt;subject_code'&gt; $subjects_result-&gt;subject_name&lt;/option&gt;";
  } 
  
  echo "&lt;/select&gt;";
  echo "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;label for='Subject'&gt;Subject Serial Number&lt;/label&gt;&lt;/td&gt;";
  echo "&lt;td&gt;";
  echo "&lt;select name='subject_serial' id = 'sub_name'&gt;";
  
  if ($semester == "SEMESTER-I")
  {
  for($i=101; $i&lt;=110; $i++ )
  { 
  echo "&lt;option value ='$i'&gt;$i&lt;/option&gt;";
  
  } 
  }
  elseif ($semester == "SEMESTER-II")
  {
  for($i=201; $i&lt;=210; $i++ )
  { 
  echo "&lt;option value ='$i'&gt;$i&lt;/option&gt;";
  } 
  }
  
  elseif ($semester == "SEMESTER-III")
  {
  for($i=301; $i&lt;=310; $i++ )
  { 
  echo "&lt;option value ='$i'&gt;$i&lt;/option&gt;";
  } 
  }
  elseif ($semester == "SEMESTER-IV")
  {
  for($i=401; $i&lt;=410; $i++ )
  { 
  echo "&lt;option value ='$i'&gt;$i&lt;/option&gt;";
  } 
  }
  
  echo "&lt;/select&gt;" ;
  echo "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  echo "&lt;/table&gt;";
  
  }
  else
  {
  return "please check the your input";
  }
  </code></pre>
  
  <p>How to add select box field dynamically after clicking add button (the selected box contain the datas from database after clicking the add button, and same selected value store in database) by using php or javascript and store selected value in selected box to database</p>