• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Auto populating textbox from selected dropdown value

#1
[eluser]Unknown[/eluser]
Hi guys,

I have a single dropdown, populated from a MySQL table tbl_venues. What I am looking to achieve, is when the user changes the value of the dropdown, two other text boxes are populated with field values that match the id of the selected venue.

I have a php array within the view that populates the dropdown, so am looking at reusing that... Possibly by converting it to a javascript array, but not sure how? The values I wish to use exist within the php array.

Here are some code snippets...

Controller
Code:
//Get venues and populate list
  $this->load->model('Catchmodel');
  $data['venues'] = $this->Catchmodel->get_venues();
  $this->load->vars($data);

View
Code:
<select name='venue' id='venue' > //assume an onchange js function is required here?
      
     &lt;?php if (count($venues)) {
      foreach ($venues as $key => $list) {
       echo "<option value='". $list['vid'] . "'>" . $list['name'] . "</option>";
      }  
     }
     echo "</select>";
     ?&gt; ///This works fine...
    </li>

    <li class="smallfield"><span class="name">Location:</span>
     &lt;input type="text"  placeholder="Nearest Town" name="location_town" id="location_town" readonly&gt; //I wish to set this value based on the selection from the dropdown
    </li>
    <li class="smallfield"><span class="name">Venue Type:</span>
     &lt;input type="text" value=""  placeholder="Venue Type" name="venue_type" id="venue_type" readonly&gt;
//I wish to set this value based on the selection from the dropdown
    </li>

Thanks in advance.


Messages In This Thread
Auto populating textbox from selected dropdown value - by El Forum - 11-04-2011, 03:07 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.