title: How to change a label value dynamically
body: <p>I want to change a label value depending on the selection made through a drop down list.
  I'm able to change the value if I create a a drop down, but when I create a label or text box, due to some mistake in the code, I'm can't change its value.</p>
  
  <p>Please have a look at my code carefully and tell me where I have to do the changes:</p>
  
  <pre><code>&lt;?php
  
  include 'connect.php';
  
  $emp_id = "";
  
  $current_coordinator_id = "";
  
  $new_coordinator_id="";
  ?&gt;
  
  &lt;?php
  
  if(isset($_POST['emp_id'])) {
      $emp_id= $_POST['emp_id'];
  }
  
  if(isset($_POST['current_coordinator_id'])) {
      $current_coordinator_id= $_POST['current_coordinator_id'];
  }
  
  if(isset($_POST['new_coordinator_id'])) {
      $new_coordinator_id= $_POST['new_coordinator_id'];
  }
  
  function Showemp_id()
  {
      $emp_id= "";
      $con = Connectdb();
      $result_function = mysqli_query($con,"SELECT * FROM dat_database.emp_hei");
      while($row = mysqli_fetch_array($result_function))
      {
          $emp_id .= '&lt;option value="' . $row['EMP_ID'] . '"&gt;' . $row['EMP_ID'] . '&lt;/option&gt;';
      }
      return $emp_id;
  }
  
  ?&gt;
  
  &lt;!doctype html public "-//w3c//dtd html 3.2//en"&gt;
  
  &lt;html&gt;
  
  &lt;head&gt;
  
      &lt;script language="javascript" type="text/javascript"&gt;
          function formValidator(){
          //alert('Out side PHP');
          // Make quick references to our field
          var emp_id = document.getElementById('emp_id');
          var current_coordinator_id = document.getElementById('current_coordinator_id');
          //var swversion = document.getElementById('swversion');
  
          // Check each input in the order that it appears in the form!
          //if(madeSelection(functional_area , "Please Choose a Functional Area")){
          //if(madeSelection(project_id , "Please Choose a Project id")){
          //if(isAlphanumeric(swversion, "Please enter a SW version. if not applicable put 'NA'.")){
          //if(madeSelection(aspice_code_id , "Please Choose a ASPICE Code id")){
          //if(madeSelection(task_id , "Please Choose a Task id")){
          //if(madeSelection(subtask_id , "Please Choose a Subtask id")){
          //if(isAlphanumeric(date, "Please enter a date.")){
          if(isNumeric(hours_spent, "Please enter the hours spent")){
          if(isAlphanumeric(defectid, "Please enter a Defect id. if not applicable put 'NA'.")){
          return true;
          }
          }
          //}
          //}
          //}
          //}
          //}
          //}
          //}
          return false;
          }
          function isNumeric(elem, helperMsg){
              var numericExpression = /^[0-9.]+$/;
  
              if(elem.value.match(numericExpression)){
                  return true;
              }else{
                  alert(helperMsg);
                  elem.focus();
                  return false;
              }
          }
          function isAlphanumeric(elem, helperMsg){
              var alphaExp = /^[0-9a-zA-Z-.]+$/;
  
              if(elem.value.match(alphaExp)){
                  return true;
  
              }else{
                  alert(helperMsg);
                  elem.focus();
                  return false;
              }
          }
  
          function madeSelection(elem, helperMsg){
          if(elem.value == "Please Choose"){
          alert(helperMsg);
          elem.focus();
          return false;
          }else{
          return true;
          }
          }
  
          &lt;/script&gt;
          &lt;script&gt;
          var maxcurrent_coordinator_idLength=0;
  
          function showcurrent_coordinator_id(str)
          {
          var xmlhttp;
          if (str.length==0)
          {
          document.getElementById("taskhint").innerHTML="";
          return;
          }
          if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
          else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
          {
          var str1=xmlhttp.responseText;
          var subStr=str1.split(",",2);
          var arrStr=subStr[0].split("#");
          if(maxcurrent_coordinator_idLength&lt;arrStr.length)
          {
          maxcurrent_coordinator_idLength=arrStr.length;
          }
  
          for(var i=0;i&lt;arrStr.length;i++)
          {
          document.getElementById("current_coordinator_id").options[i]=new Option(arrStr[i]);
          document.getElementById("current_coordinator_id").options[i].innerText=arrStr[i];
          }
  
          for(var j=arrStr.length;j&lt;maxcurrent_coordinator_idLength;j++)
          {
          document.getElementById("current_coordinator_id").remove(arrStr.length);
          }
          }
          }
          xmlhttp.open("GET","http://10.129.65.230/subcordinator.php?r="+str,true);
          xmlhttp.send();
          }
  
      &lt;/script&gt;
      &lt;link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"&gt;
      &lt;script src="//code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
      &lt;script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" href="/resources/demos/style.css"&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;!-- Set the viewport width to device width for mobile --&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
      &lt;section class="examples white page-title"&gt;
      &lt;div class="row"&gt;
      &lt;div class="nine columns"&gt;
      &lt;div class="twelve columns"&gt;
      &lt;div class="fsBody fsEmbed"&gt;
  
      &lt;form onsubmit="return formValidator()" action=''" method="POST" accept-charset="UTF-8" novalidate enctype="multipart/form-data" class="fsForm fsSingleColumn" id="fsForm1428139"&gt;
      &lt;div role="alert" id="submittingText" style="display:none;"&gt;Submitting&lt;/div&gt;
      &lt;p class="fsSectionHeading" style="text-align: center;"&gt;
      &lt;/p&gt;
      &lt;p style="text-align: center;"&gt;
      &lt;span style="font-size: 24px;"&gt;Update Coordinator_ID&lt;/span&gt;
      &lt;/p&gt;
  
      &lt;p class="fsSectionText" style="text-align: center;"&gt;
      Please fill out required information below.
      &lt;/p&gt;
  
      &lt;table style="width:100%"&gt;
  
  
      &lt;tr&gt;
      &lt;td&gt;&lt;label class="fsSupporting" style="margin-left:50px; for="emp_id"&gt;EMP_ID&lt;/label&gt;&lt;/td&gt;
      &lt;td&gt;&lt;select name="emp_id"  id="emp_id" onchange="showcurrent_coordinator_id(this.value)" required="" style="width: 214px; margin-top:5px; class="fsField fsFieldState fsRequired" aria-required="true"&gt;
      &lt;option value=""&gt;----- Select -------&lt;/option&gt;
      &lt;?php echo Showemp_id(); ?&gt;
      &lt;/select&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;label class="fsSupporting" style="margin-left:50px; for="current_coordinator_id"&gt;Current Coordinator ID&lt;/label&gt;&lt;/td&gt;
      &lt;td&gt; 
      &lt;select name="current_coordinator_id" size="1" multiple id="current_coordinator_id" required="" style="width: 214px; margin-top:5px; class="fsField fsFieldState fsRequired"&gt;
      &lt;/select&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
      &lt;td&gt;&lt;label class="fsSupporting" style="margin-left:50px; for="current_coordinator_id"&gt;New Coordinator ID&lt;/label&gt;&lt;/td&gt;
      &lt;td&gt;
  
      &lt;input type="text" id="new_coordinator_id" name="new_coordinator_id" size="50" required style="width: 200px; margin-top:5px; class="fsField fsFormatPhoneUS fsRequired" aria-required="true"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;br&gt;
  
      &lt;p class="fsSectionText" style="text-align: center;"&gt;
      &lt;input id="fsSubmitButton1428139" class="fsSubmitButton" style="width: 200px; color: rgb(0, 0, 0); background: rgb(180, 86, 146);" type="submit" value="Submit" onClick="formValidator()" /&gt;
      &lt;/p&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  
  &lt;?php
  
      $conn=mysqli_connect("localhost","root","mmint123","dat_database");
  
      $query = "UPDATE dat_database.emp_hei SET coordinator_id='$new_coordinator_id'  WHERE EMP_ID='$emp_id'";
  
      mysqli_query($conn,$query) or die('Error, query failed'); 
  
  
      if ($query &gt; 0)
      {
          echo "&lt;script type='text/javascript'&gt;alert('Coordinator_id updated successfully!')&lt;/script&gt;";
      }
  
  ?&gt;
  
  
  &lt;!-- You can place html anywhere within the source tags --&gt;
  
  
  &lt;script language="javascript" type="text/javascript"&gt;
  // You can place JavaScript like this
  
  &lt;/script&gt;
  &lt;?php
  // You can place PHP like this
  
  ?&gt;
  </code></pre>