Welcome Guest, Not a member yet? Register   Sign In
Is there a way I can auto fill a text area based on a selectbox drop down?

I'm trying to auto fill a textarea based on the selection of a selectbox.

I want the auto fill text to come from my database and it would be nice if the option names in the selectbox could come from the database also, but not necessary - they can be static.

I'm sure I will have to use some kind of JavaScript or Json, etc. Any help you can give I appreciate it.

(This post was last modified: 11-19-2014, 04:22 PM by Rufnex.)

Ok, lets think about that your database have a table with the otpions and the related information (title, information).

Make a model with a method that gives you back the table data. Call it form the controller and route it to the view. In the view loop over the data an build the option fields.

Thats for the part 1. If the information you want to put into the textarea is not to long you can do it directyl. otherwise it could be an idea to do it with an ajax request. I would recommend to use jQuery. Look at the following untested example as a kind of blueprint.

PHP Code:
public function get_options()
$query $this->db->get('options');
$query->num_rows() > 0)

PHP Code:
public function index()
$this->data['options'] = $this->your_model->get_options();

PHP Code:
<select id="example">
php foreach($optionsas $option): ?>
    <option data-info="<?php echo $option['information']; ?>"><?php echo $option['title']; ?></option>
    <?php endforeach; ?>

<textarea id="info"></textarea>

<script src="...jquery..."></sript>
$(document).ready(function() {
        $('#info').val( $(this).find('option:selected').data('info') ); 

If it is ok by that way fine .. otherwise you have to user ajax .. let me here ^^.


Thanks, I'll try this

Theme © iAndrew 2016 - Forum software by © MyBB