How do get a function value to $_POST
<p>So I am trying to get this function that is a state dropdown selection for form to give me the value of what is selected when submitted using $_POST in another file the thing is I don't really know how to when your using 'name=' a parameter that is sent in.</p>

<p>Here is my code</p>

<pre><code>&lt;?php
    function state_select ($name,$full_state,$selected = '') {

  $state_list = array("AL|Alabama","AK|Alaska","AZ|Arizona", "AR|Arkansas", "CA|California", "CO|Colorado", "CT|Connecticut", "DE|Delaware", "DC|Washington D.C.", "FL|Florida", "GA|Georgia", "HI|Hawaii", "ID|Idaho", "IL|Illinois", "IN|Indiana", "IA|Iowa", "KS|Kansas", "KY|Kentucky", "LA|Louisiana", "ME|Maine", "MD|Maryland", "MA|Massachusetts", "MI|Michigan", "MN|Minnesota", "MS|Mississippi", "MO|Missouri", "MT|Montana", "NE|Nebraska", "NV|Nevada", "NH|New Hampshire", "NJ|New Jersey", "NM|New Mexico", "NY|New York", "NC|North Carolina", "ND|North Dakota", "OH|Ohio", "OK|Oklahoma", "OR|Oregon", "PA|Pennsylvania", "RI|Rhode Island", "SC|South Carolina", "SD|South Dakota", "TN|Tennessee", "TX|Texas", "UT|Utah", "VT|Vermont", "VA|Virginia", "WA|Washington", "WV|West Virginia", "WI|Wisconsin", "WY|Wyoming");

  ?&gt;
  &lt;select name=&lt;?=$name;?&gt; id="state" &gt;&lt;?
    foreach ($state_list as $s) {
        $values = explode("|",$s);
        ?&gt;&lt;option value="&lt;?=$values[0];?&gt;" &lt;?
                if($selected == $values[0]) { ?&gt;SELECTED&lt;? }
                ?&gt;&gt;
                &lt;? if($full_state) { ?&gt;&lt;?=$values[1];?&gt;&lt;? } else { ?&gt;&lt;?=$values[0];?&gt;&lt;? } ?&gt;&lt;/option&gt;&lt;?
    }
  ?&gt;&lt;/select&gt;&lt;?
}
?&gt;


&lt;span class="InputDiscription"&gt;State: &lt;/span&gt;&lt;div class="InputInner"&gt;&lt;?=state_select('state',false,'AL'); ?&gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 

?&gt;
</code></pre>

<p>Thank you!</p>

<p>UPDATED_<strong><em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__</strong></p>

<p>file that value is sent to ---</p>

<pre><code> $selectvalue=$_POST['hiddenfield'];
    echo $selectvalue;
</code></pre>

<p>main file!</p>

<pre><code>&lt;head&gt;  
&lt;script type="text/javascript"&gt;
function submitform(){
    // Get the index of selected item
    var list = document.getElementById('state');
    var INDEX = list.selectedIndex;
    document.getElementById("hiddenfield").value=list[INDEX].value;

    //Submit the form
    document.forms["theform"].submit();
}
&lt;/script&gt;
&lt;/head&gt;
    &lt;div class="InputContainer"&gt;
    &lt;!------------------------------------------STATE SELECTION CODE -------------------------------------------&gt;
&lt;?php
    function state_select ($name,$full_state,$selected = '') {

  $state_list = array("AL|Alabama","AK|Alaska","AZ|Arizona", "AR|Arkansas", "CA|California", "CO|Colorado", "CT|Connecticut", "DE|Delaware", "DC|Washington D.C.", "FL|Florida", "GA|Georgia", "HI|Hawaii", "ID|Idaho", "IL|Illinois", "IN|Indiana", "IA|Iowa", "KS|Kansas", "KY|Kentucky", "LA|Louisiana", "ME|Maine", "MD|Maryland", "MA|Massachusetts", "MI|Michigan", "MN|Minnesota", "MS|Mississippi", "MO|Missouri", "MT|Montana", "NE|Nebraska", "NV|Nevada", "NH|New Hampshire", "NJ|New Jersey", "NM|New Mexico", "NY|New York", "NC|North Carolina", "ND|North Dakota", "OH|Ohio", "OK|Oklahoma", "OR|Oregon", "PA|Pennsylvania", "RI|Rhode Island", "SC|South Carolina", "SD|South Dakota", "TN|Tennessee", "TX|Texas", "UT|Utah", "VT|Vermont", "VA|Virginia", "WA|Washington", "WV|West Virginia", "WI|Wisconsin", "WY|Wyoming");

  ?&gt;
  &lt;select name=&lt;?=$name;?&gt; id="state" &gt;&lt;?
    foreach ($state_list as $s) {
        $values = explode("|",$s);
        ?&gt;&lt;option value="&lt;?=$values[0];?&gt;" &lt;?
                if($selected == $values[0]) { ?&gt;SELECTED&lt;? }
                ?&gt;&gt;

                &lt;?  if($full_state) { ?&gt;&lt;?=$values[1];?&gt;&lt;? } else { ?&gt;&lt;?=$values[0];?&gt;&lt;? } ?&gt;&lt;/option&gt;&lt;?
    }
  ?&gt;&lt;/select&gt;&lt;?
}
?&gt;




&lt;span class="InputDiscription"&gt;State: &lt;/span&gt;&lt;div class="InputInner"&gt;
&lt;?=state_select('state',false,'AL'); ?&gt;
 &lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;input type="hidden" id="hiddenfield" name="hiddenfield" value=""&gt;
&lt;?php

 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 

?&gt;

&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
</code></pre>

<p>updated------------------------------------------------------------------------
main file-------------</p>

<pre><code>&lt;html&gt;
&lt;head&gt;  
&lt;script type="text/javascript"&gt;
function submitform(){
    // Get the index of selected item
    var list = document.getElementById('state');
    var INDEX = list.selectedIndex;
    document.getElementById("hiddenfield").value=list[INDEX].value;

    //Submit the form
    document.forms["theform"].submit();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php
include('Main.css');

$hostname="";
$username="";
$password="";
$database="";

/*mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");*/

//function getFN(){
try {  
  # MySQL with PDO_MYSQL  
  $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
  $DBH-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

  //$DBH-&gt;prepare('SELECT first FROM contacts');
}  
catch(PDOException $e) { 
    echo "I'm sorry, I'm afraid I can't do that.";  
    file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND);   
}  
//get query
$FNresult=$DBH-&gt;query('SELECT CompanyNames FROM companynames'); 
//set fetch mode
$FNresult-&gt;setFetchMode(PDO::FETCH_ASSOC);

$DBH = null; 
?&gt;


        &lt;div id="MainContainer"&gt;   
            &lt;h2 align="center"&gt;
                &lt;u&gt;PLEASE SUPPLY THE FOLLOWING INFORMATION REGARDING YOUR AUTO INSURANCE POLICY:&lt;/u&gt;
           &lt;/h2&gt;

         &lt;div class="FormContainer"&gt;
            &lt;form name="theform" action="insert.php" method="post"&gt;
                &lt;div class="CheckBoxContainer"&gt;
            &lt;input type="checkbox" value"On" name="only-thisform"/&gt;I will complete the insurance verification form only. 
            &lt;?php 
            $setError=$_GET['seterror'];

            if ($setError == 1){

                echo "&lt;div class='errorMsg'&gt; *Required&lt;/div&gt;";
            }
             ?&gt;
            &lt;br&gt;
            &lt;br&gt;

            &lt;input type="checkbox"  value="On" name="approval" id="approval"/&gt;I agree to authorize PCG Protects, LLC to receive a certificate of liability and or to be added as an additional interest on my personal auto policy, whichever accommodates my Auto Insurance Carriers standard practice, so they can monitor the active status of my personal auto policy, on behalf of my employer.
             &lt;?php 
             $setError=$_GET['seterror'];
             if ($setError == 1){

                echo "&lt;div class='errorMsg'&gt; *Required&lt;/div&gt;";
             }

             ?&gt;
            &lt;/div&gt;&lt;!------------------------------------END   .CheckBoxContainer -------------------------------------------&gt;
            &lt;br&gt;
            &lt;br&gt;


&lt;script type="text/javascript"
     src="http://code.jquery.com/jquery-latest.min.js"&gt;
&lt;/script&gt;   
&lt;!-- javascript on client-side --&gt;


&lt;div class="DropDownSelector"&gt;
&lt;?php

$dropdown = "&lt;select name='CompanyNames' id='CompanyNames' &gt;";

$dropdown .= "\r\n&lt;option  id ='other' name ='other' value='other'&gt;other&lt;/option&gt;";

while($row =$FNresult-&gt;fetch()) {

  $dropdown .= "\r\n&lt;option  id ='firstname' name ='first' value='{$row['CompanyNames']}'&gt;{$row['CompanyNames']}&lt;/option&gt;";
}

$dropdown .= "\r\n&lt;/select&gt;";

echo $dropdown;
?&gt;
    &lt;div class="DropdownDiscription"&gt;Please select your insurance company.  Select other if you do not see it listed. &lt;/div&gt;
&lt;/div&gt; &lt;!------------------------------------------END .DropDownSelector --------------------------------------------------------&gt;
&lt;script type="text/javascript"&gt;  

var dropdown = $('#CompanyNames');
//var test = $('#firstname');
//document.write(dropdown.val());

dropdown.bind('change', function(){

    $.post('backgroundScript.php', 
        { 
            'CompanyNames': dropdown.val()

        },
        function(response) {
            $('#compname').val(response.Companyname);
            //$('#phone').val(response.phone);
            //$('#policynum').val(response.policynum);
            //$('#nameofPolicyholder').val(response.policyholder);
            //$('#mailing').val(response.mailing);
            // Repeat for all of your form fields
        },
        'json'
    );

});
&lt;/script&gt;
&lt;br&gt;
&lt;div class="FormBody"&gt;
    &lt;div class="InputContainer"&gt;
&lt;span class="InputDiscription"&gt;Insurance Company Name: &lt;/span&gt;&lt;div class="InputInner"&gt; &lt;input type="text" name="compname" id="compname" &gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;

&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 
?&gt;

&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
    &lt;div class="InputContainer"&gt;
&lt;span class="InputDiscription"&gt;Insurance Phone number: &lt;/span&gt;&lt;div class="InputInner"&gt;&lt;input type="text"  name="phone" id="phone"&gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 
?&gt;

&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
    &lt;div class="InputContainer"&gt;
&lt;span class="InputDiscription"&gt;Policy Number: &lt;/span&gt;&lt;div class="InputInner"&gt;&lt;input type="text" name ="policynum" id="policynum"&gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 
?&gt;

&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
    &lt;div class="InputContainer"&gt;
&lt;span class="InputDiscription"&gt;Name of the Policyholder: &lt;/span&gt;&lt;div class="InputInner"&gt;&lt;input type="text" name="nameofPolicyholder" id="nameofPolicyholder"&gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 
?&gt;


&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
    &lt;div class="InputContainer"&gt;
&lt;span class="InputDiscription"&gt;Policyholder mailing address: &lt;/span&gt;&lt;div class="InputInner"&gt;&lt;input type="text" name="mailing" id="mailing"&gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 
?&gt;

&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
    &lt;div class="InputContainer"&gt;
&lt;span class="InputDiscription"&gt;City: &lt;/span&gt;&lt;div class="InputInner"&gt;&lt;input type="text" name="city" id="city"&gt;&lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;?php
 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 
?&gt;


&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
    &lt;div class="InputContainer"&gt;
    &lt;!------------------------------------------STATE SELECTION CODE -------------------------------------------&gt;
&lt;?php
    function state_select ($name,$full_state,$selected = '') {

  $state_list = array("AL|Alabama","AK|Alaska","AZ|Arizona", "AR|Arkansas", "CA|California", "CO|Colorado", "CT|Connecticut", "DE|Delaware", "DC|Washington D.C.", "FL|Florida", "GA|Georgia", "HI|Hawaii", "ID|Idaho", "IL|Illinois", "IN|Indiana", "IA|Iowa", "KS|Kansas", "KY|Kentucky", "LA|Louisiana", "ME|Maine", "MD|Maryland", "MA|Massachusetts", "MI|Michigan", "MN|Minnesota", "MS|Mississippi", "MO|Missouri", "MT|Montana", "NE|Nebraska", "NV|Nevada", "NH|New Hampshire", "NJ|New Jersey", "NM|New Mexico", "NY|New York", "NC|North Carolina", "ND|North Dakota", "OH|Ohio", "OK|Oklahoma", "OR|Oregon", "PA|Pennsylvania", "RI|Rhode Island", "SC|South Carolina", "SD|South Dakota", "TN|Tennessee", "TX|Texas", "UT|Utah", "VT|Vermont", "VA|Virginia", "WA|Washington", "WV|West Virginia", "WI|Wisconsin", "WY|Wyoming");

  ?&gt;
  &lt;select name=&lt;?=$name;?&gt; id="state" &gt;&lt;?
    foreach ($state_list as $s) {
        $values = explode("|",$s);
        ?&gt;&lt;option value="&lt;?=$values[0];?&gt;" &lt;?
                if($selected == $values[0]) { ?&gt;SELECTED&lt;? }
                ?&gt;&gt;

                &lt;?  if($full_state) { ?&gt;&lt;?=$values[1];?&gt;&lt;? } else { ?&gt;&lt;?=$values[0];?&gt;&lt;? } ?&gt;&lt;/option&gt;&lt;?
    }
  ?&gt;&lt;/select&gt;&lt;?
}
?&gt;




&lt;span class="InputDiscription"&gt;State: &lt;/span&gt;&lt;div class="InputInner"&gt;
&lt;?=state_select('state',false,'AL'); ?&gt;
 &lt;/div&gt;&lt;!----- END .InputInner ----------&gt;
&lt;input type="hidden" id="hiddenfield" name="hiddenfield" value=""&gt;
&lt;?php

 $setError=$_GET['seterror']; 
if($setError == 1){
    echo "&lt;span class='errorMsg'&gt;*Required&lt;/span&gt;";
    }
else
    echo "&lt;span&gt;*&lt;/span&gt;"; 

?&gt;

&lt;/div&gt;&lt;!---------------------------------END .InputContaienr -----------------------------------&gt;
&lt;br&gt;
&lt;?php 
 $setError=$_GET['seterror']; 
if($setError == 1){
echo "&lt;script type='text/javascript'&gt;alert('Please check to make sure all required fields are filled out!');&lt;/script&gt;";
}
?&gt;
&lt;input type="Submit" name="Submit" &gt;

&lt;/div&gt;&lt;!-------------------------------------------END .FormBody -------------------------------------------------------&gt;
&lt;/form&gt;


    &lt;/div&gt;&lt;!--------------------------------------End .FormContainer ----------------------------------------------&gt;

&lt;/div&gt;&lt;!----------------------------------End #MainContainer-----------------------------------&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>other file----------------
everything is commenteed off except for that one display code
    /
        /<strong>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>***</strong><em>VALIDATE CHECK BOXES ARE CHECKED <strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**</strong>/
            /*  $setError = 0;
                $ch1 = 'unchecked';
                $ch2 = 'unchecked';
            //  print_r("testing ch1 : $ch1");
                if(isset($_POST['only-thisform']))  {</p>

<pre><code>                $ch1 = 'Check';
                //if ($setChecker != 1)
                $setError= 0;
                //print_r("testing ch1: $ch1");

            }
            if ($ch1 !='Check' ){

            $setError = 1;
            returnBack();

        }
            if (isset($_POST['approval'])) {
                //$setChecker = 1;
                $ch2 = 'Check';
                $setError= 0;
                //print_r("testing  ch2: $ch2");
            }
             if ($ch2 != 'Check' ){

            $setError = 1;
            returnBack();

        }*/
/***************************************************************************************************************************************/       
        /* 
function returnBack(){
    header("Location: http://pcgprotects.com/PCG/test.php?seterror=1");
    exit;

}


if(isset($_POST['compname']))  {
    $compname=$_POST['compname'];
}
else{
    $setError = 1;
    returnBack();
}

if(isset($_POST['phone']))  {
    $phone=$_POST['phone'];
}
else{
    $setError = 1;
    returnBack();
}

if(isset($_POST['policynum']))  {
    $policynum=$_POST['policynum'];
}
else{
    $setError = 1;
    returnBack();
}

if(isset($_POST['nameofPolicyholder']))  {
    $nameofPolicyholder=$_POST['nameofPolicyholder'];
}
else{
    $setError = 1;
    returnBack();
}

if(isset($_POST['mailing']))  {
    $mailing=$_POST['mailing'];
}
else{
    $setError = 1;
    returnBack();
}
if(isset($_POST['city']))  {
    $city=$_POST['city'];
}
else{
    $setError = 1;
    returnBack();
}
if(isset($_POST['mailing']))  {
    $mailing=$_POST['mailing'];
}
else{
    $setError = 1;
    returnBack();
}
*/

    echo "hiddenfield=".$_POST['hiddenfield'];

/*
mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$new_id_number = mysql_insert_id();
$query = "INSERT INTO contacts VALUES ('$new_id_number','$compname','$phone','$policynum','$nameofPolicyholder','$mailing')";
echo 'being inserted';
mysql_query($query);

if ('SELECT * FROM companynames WHERE CompanyNames != :compname');{
    $query = "INSERT INTO companynames VALUES('$new_id_number','$compname')";
    mysql_query($query);
    echo "working";
}
mysql_close();*/
?&gt;
</code></pre>
