RalphLeMouf Posted January 8, 2013 Share Posted January 8, 2013 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 Link to comment https://forums.phpfreaks.com/topic/272867-what-is-the-best-way-to-add-keyup-function-to-codeigniter-form_textarea/ Share on other sites More sharing options...
cpd Posted January 8, 2013 Share Posted January 8, 2013 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. Link to comment https://forums.phpfreaks.com/topic/272867-what-is-the-best-way-to-add-keyup-function-to-codeigniter-form_textarea/#findComment-1404294 Share on other sites More sharing options...
kareem3d Posted January 22, 2013 Share Posted January 22, 2013 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)'); }); }); Link to comment https://forums.phpfreaks.com/topic/272867-what-is-the-best-way-to-add-keyup-function-to-codeigniter-form_textarea/#findComment-1407517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.