简体   繁体   中英

CodeIgniter - Populating textboxes from dropdown

Im working on a CodeIgniter project at the moment and am having big problems with one of the functions.

I have a dropdown menu with a list of names and 2 textboxes which need to be populated by the name and code.

What i need to do, is when a user clicks on one of the names in the dropdown, the textfields automatically gets populated by the name and code associated with the name in the dropdown.

I have tried solutions and been searching for example code everywhere, but i cant seem to get anything that works.

Im hoping someone here can help me out some with source code.

Thanks all,

This isn't a CodeIgniter issue at all. It sounds like you are looking for some JavaScript assistance - you also need to go into a bit more detail on "the code associated with the name in the dropdown". What code, how is it associated, where is this data stored? Additionally, a dropdown isn't a valid HTML element so I am going to assume you are using a select input element.

Here's a bit of HTML and jQuery code, that should get you moving in the right direction a little bit.

<select name="nameList" id="nameList" size="1">
  <option value="1">Michael Jackson</option>
  <option value="2">Michael Jordan</option>
  <option value="3">Michael Wales</option>
</select>

<textarea name="nameDetails" id="nameDetails"></textarea>

And the jQuery to place the selected name in the textarea:

$('#nameList').change(function() {
  var selectedName = $('#nameList option:selected').text();
  $('#nameDetails').text(selectedName);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM