javascript - How to make HTML form fields automatically change when an option selected on a select field -


let's have form in codeigniter project.

<?php echo form_open(); ?>     <select>         <?php foreach($status_list $status): ?>         <option value="<?php echo $status->id; ?>"><?php echo $status->name; ?></option>         <?php endforeach; ?>     </select>     <!-- show if status type is, let's "e" -->     <input type="text" name="e_happened">     <!-- show if status type is, let's "s" -->     <input type="text" name="s_happened"> <?php echo form_close(); ?> 

what want if user select 1 status, according it's type, show text field input.

i've made way type of status this: http://localhost/myapp/index.php/status/type/{status_id} users can pass status id , "echo" type of status.

i want receive html page via javascript method , show text input fields. how do that?

thank you. :)

as have jquery tag, suggest this:

$('select').change(function(){     var inp = this.value.trim();     $(this).parent().find('input[type="text"][name^="'+inp+'"]').show().siblings(':text').hide(); }); 

Comments

Popular posts from this blog

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -