Jump to content

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


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

});
});

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.