Jump to content

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


RalphLeMouf

Recommended Posts

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 weeks later...

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)');

});
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.