Champion
Champion

Reputation: 774

How to show input based on previous selected option PHP?

I have a form with many fields and I need to get several values only after selected specific field. For example after page loaded div2 gets value, probably random or last array's company Id ... but I need this value should be empty and after selected div1 it changes to that id (div1's id).

<div id="1">
<label>Name</label>
  <select id="select-company" name="company_id">
    <?php
     foreach($companies as $company){
       $company = (object)$company['Company'];
       echo '<option value="" disabled selected >select</option>';
       echo '<option value="'.$company->id.'">'. $company->display_name .'</option>';
     }
    ?>
  </select>
</div>

<div id="2">
  <label>ID </label><br>
  <input name="id" value="'. $company->id .'"/>
</div>

How can I get company Id in div2 only after value selected from div1? All data is already presented on page (in var_dump($companies)).

Upvotes: 0

Views: 189

Answers (1)

B_Sharp
B_Sharp

Reputation: 11

If the data company id,name ..etc is from database you need javascript + php ( ajax ).

Upvotes: 1

Related Questions