CodeIgniter Forums
How to get one form_input to show up in another? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How to get one form_input to show up in another? (/thread-64984.html)



How to get one form_input to show up in another? - doomie22 - 04-17-2016

Hi there,

I am just wondering if there is a way of having a non-usable input section show up what someone is typing in another input?

Thanks,

Doomie


RE: How to get one form_input to show up in another? - acsv - 04-17-2016

If you want this in real time you would probably want to use javascript.


RE: How to get one form_input to show up in another? - doomie22 - 04-18-2016

I have found a couple but none of them seems to want to work with my form  Huh


RE: How to get one form_input to show up in another? - Wouter60 - 04-18-2016

jQuery is your best friend.
Load the jQuery library in your page's head section.
Then, at the bottom of your page (preferrably after the </body> tag):
Code:
<script>
$(document).ready(function() {
  $('#input1').keyup(function() {
      var text = $('#input1').val();
      $('#input2').val(text);
  });
});
</script>
In this example, "input1" is the id attribute of the input where the user is typing text, and "input2" is the id of the second field where you want to show the text that is being typed.
More info: https://api.jquery.com/keyup/


RE: How to get one form_input to show up in another? - doomie22 - 04-21-2016

I have been trying to mess around to get this to work.  The following 2 lines are the part of the comlpete form that I want it to copy to.

PHP Code:
<?php echo form_input(array('id' => 'input1''name' => 'name''class' => 'form-control'),'' $js); ?>
<?php 
echo form_input(array('id' => 'input2''name' => 'url''class' => 'form-control'),'' $js); ?>

I have added the code in the above post and added jquery and it just seems to do nothing and I cannot see why.


RE: How to get one form_input to show up in another? - Wouter60 - 04-21-2016

You didn't describe the value of the $js variable, but in general, jQuery can handle elements by their id or class.
It should work if you do this:

PHP Code:
<?php echo form_input(array('id' => 'input1''name' => 'name''class' => 'form-control')); ?>
<?php 
echo form_input(array('id' => 'input2''name' => 'url''class' => 'form-control')); ?>

<script>
 $(document).ready(function() {
   $('#input1').keyup(function() {
       var text = $('#input1').val();
       $('#input2').val(text);
   });
 });
 </script>