Jump to content


Photo

What is the best way to add keyup function to codeigniter form_textarea?


  • Please log in to reply
2 replies to this topic

#1 RalphLeMouf

RalphLeMouf

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 08 January 2013 - 02:23 PM

Hello -

I am trying to add a counter that starts with the maximum number of characters a lotted and counts backwards as the user types until they reach their limit. I'm assuming the best way to do this is with jquery keyup, however I have tried A BUNCH of different snippets of jquery and I am not able to integrate it within the codeigniter format. What is the best way to do this with codeiginter?

Here is my I am trying to add it to. I would prefer to leave my structure as is and just add what is needed.


<div class="edit_section_title">
My Life <br />Tell us a about yourself <span class="edit_sub_text">(1350 character limit)</span>
</div>
<div class="edit_text_area"> 
<?php 

if(empty($user['mylife']))
{
echo form_textarea('mylife');
}
else
{
echo form_textarea('mylife', $user['mylife']);
}


?>
</div>

thanks so much in advance

#2 cpd

cpd

    ¬_¬

  • Members
  • PipPipPip
  • 881 posts
  • LocationLondon, UK

Posted 08 January 2013 - 02:58 PM

Create a Javascript file and include it in the header. The file should contain the logic for adjusting the character counter - possibly register a "keyUp" event listener as well.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

"One of my most productive days was throwing away 1000 lines of code."

#3 kareem3d

kareem3d

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 22 January 2013 - 12:43 PM

Add this javascript code ( you have to include jquery )
$(document).ready(function()
{
$('[name="mylife"]').keypress(function(e){
 
  var length = $('[name="mylife"]').val().length;

  $(".edit_sub_text").html('(' + (1350 - length) + 'character limit)');

});
});





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com