JavaScript - Limit Lines And Charachters In A Textarea
Hi - I have the following requirement for a textarea:
Limit the number of lines to 8 Limit the number of characters to 20 per line Force a line beak when the user reaches he end of a line but break the line at the start of the last word (not half way through the word). Allow pasting into the field and auto-format the line/character count Keep he cursor where it should be (don't move it to the end of the field after any formatting) This is more complicated than it sounds - anyone worked on something similar? Similar TutorialsIs it possible to limit a textarea input with a max amount of letters? So if the form said 1,000 character limit. Can it block it after the 1,000th one is reached? hello, i want to make a word limit on textarea in the below form any body help me- thank you. please reply me by editing below code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>freebacklinkcreator.blogspot.com submit form</title> </head> <body> <form method="post" action="sendeail.php"> <!-- DO NOT change ANY of the php sections --> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> Your Name: <br /> <select name="visitor" size="1"> <option value=" Business ">Business </option> <option value=" Finance ">Finance </option> <option value=" Reference ">Reference </option> <option value=" Shopping ">Shopping </option> <option value=" Arts and Entertainment ">Arts and Entertainment </option> <option value=" Computers ">Computers </option> <option value=" Health ">Health </option> <option value=" News and Media ">News and Media </option> <option value=" Regional ">Regional </option> <option value=" Society ">Society </option> <option value=" Education ">Education </option> <option value=" Internet ">Internet </option> <option value=" Recreation ">Recreation </option> <option value=" Science and Technology ">Science and Technology </option> <option value=" Sports ">Sports </option> <option value=" Jobs ">Jobs </option> <option value=" Online ">Online </option> <option value=" Money ">Money </option> <option value=" Affiliate Programs ">Affiliate Programs </option> </select> <br /> Your Email:<br /> <input type="text" name="visitormail" size="35" /> <br /> <br /> <br /> Site Title:<br /> <input type="text" name="attn" size="35" /> <br /><br /> Site Description: <br /> <textarea name="notes" "rows="4" cols="40"></textarea> <br /> <input type="submit" value="Send Mail" /> <br /> </form> </body> </html> Has anyone ever tried to break up a text area into 2 lines, but at the same time each line has a limited number of characters allowed in it ? i.e. line 1 = maxcharacters = 124 , line 2 = machcharacters = 1024 (Line 2 will therefore wrap until 1024 chracters are reached) ... including spaces as characters. Something along the lines of: Code: var maxLines = txtArea.rows; var maxChars = txtArea.rows * txtArea.cols; countChars.value = txtArea.value.length; countLines.value = getLines(txtArea); document.myForm.maxLines.value = maxLines; document.myForm.maxChars.value = maxChars; if((txtArea.value.length >= maxChars || getLines(txtArea) >= maxLines) && (window.event.keyCode == 10 || window.event.keyCode == 13)) { while(getLines(txtArea) > maxLines) txtArea.value = txtArea.value.substr(0,txtArea.value.length-2); while(txtArea.value.length > maxChars) txtArea.value = txtArea.value.substr(0,txtArea.value.length-2); alert("chars and / or lines limit reached"); } else if(txtArea.value.length > maxChars ) { while(txtArea.value.length > maxChars) { txtArea.value = txtArea.value.substr(0,txtArea.value.length-1); } alert("chars limit reached"); } else if (f (countLines.value > maxLines) { while(countLines.value > maxLines) { txtArea.value = txtArea.value.substr(0,txtArea.value.length-1); } alert("lines limit reached"); } countChars.value = txtArea.value.length; countLines.value = getLines(txtArea); } Thanks Hi i have a problem, i've been trying to fix this for the whole day pls see my code below Code: for ($o = 0; $o <= $totalclass; $o++) { for($i = 1; $i <= 45; $i++) { if ($_SESSION['classification'][$o] == $i) { $sql2="SELECT ClassDesc FROM tblclass WHERE ClassID = '$i'"; $result2=mysql_query($sql2); // If successfully queried if($result2) { while ($row2 = mysql_fetch_assoc($result2)) { $ClassDesc2 = $row2['ClassDesc']; } } //echo $ClassDesc2; ?> <tr> <td bgcolor="FAFAF6" class="small" valign="top">Class <? echo $i; ?></td> <input type="hidden" name="<? echo "classid[]"; ?>" value="<? echo $i; ?>"> <td bgcolor="FAFAF6"> <textarea name="<? echo "specification[]"; ?>" COLS="50" ROWS="6" class="small" wrap="virtual" tabindex="<? echo $i; ?>"><? echo $ClassDesc2;?></textarea> <input type="button" value="Reset" onclick="window.reset();" name="reset"> </td> </tr> <? } } } i've trying to create a button or image to reset one textarea (from whole array) and so far i've been unsuccessful. i've seen this on other website and i know it is possible to do this, pls help! Hello every body i have a problem with javascript i wrote a script which process the entry of a text area 1 and i made the script process only the first line of the entry i want a method to make the script to process all of the lines which the user enter it OR make a varibals to every line entered from the user i am so sorry about the weak language thank you in advance Dear Friends, please give your solution about below problem. I call function test".$i."(){ edit($('$paket_id')); } function for editing in line text. <div onclick="test".$i."(this)"><img src="./images/edit01.png"></div> http://www.freeimagehosting.net/l5raa But when I click to call link, the textarea are opening again. How I can limit this? i have a program which gets values from different arrays and displays them on screen. how do i insert a break every 5 lines so its easier to read?
I have a script which allow a user to move users from one multiple selectbox to another and it works fine, but... I want to be able to restrict a user to only move x amount of users from one box to another. I want to create an alert when the user try to add a user to much... The javascript: Code: $().ready(function() { $('#add').click(function() { return !$('#box1 option:selected').remove().appendTo('#box2'); }); $('#remove').click(function() { return !$('#box2 option:selected').remove().appendTo('#box1'); }); }); The HTML: Code: <table> <tr> <td valign="top"><select multiple id="box2" style="width:250px;height:200px;"></select></td> <td width="100%" align="center"><a href="#" id="add">Add</a><br><a href="#" id="remove">Remove</a></td> <td valign="top"> <select multiple id="box2" style="width:250px;height:200px;"> <option value="1">User 1</option> <option value="2">User 2</option> <option value="3">User 3</option> <option value="4">User 4</option> </select> </td> </tr> </table> Hope this makes sense... Thanks in advance... hi, i am now playing with the time. can you please tell me how to make the time move in downwards, i mean a countdown like format, e.g the time will start countdown and end in 2 days? here's my initial noob code for creating time Code: <script type="text/javascript"> var today = new Date(); h = today.getHours(); m = today.getMinutes(); s = today.getSeconds(); function showDate(){ if(document.getElementById('but').value = "locked"){ h = checktime(h); m = checktime(m); s = checktime(s); } document.getElementById('t').innerHTML = h +":"+m+":"+s; } function checktime(i){ if(i < 10){ i = "0" + i; } return i; } function ocl(){ var x = true; if(x){ document.getElementById('but').value = "locked"; showDate(); } } function mo(){ document.getElementById('but').value = "lock me ?"; x = false; } </script> <h3> <a id="t"></a> </h3> <input type="button" id="but" value="unlocked" onmouseover="mo();" onclick="ocl();" /> Hi All I am not a genius when it comes to javascript so if anyone could help, I would really be grateful. scenario: I am creating a custom product (75g) which will be made up of 3 others products (25g + 25g + 25g). The 3 options will be made up of a combination of smaller products each with their own options (25g, 50g, 75g) which will allow the customer to have one of each or fill up all 3 with just one type. Here is what I have in code already: Code: <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Sour Worms</h4> <div class="back"> <input name="id[14][48]" value="48" id="attrib-14-48" type="checkbox"><label class="attribsCheckbox" for="attrib-14-48">25g</label><br> <input name="id[14][49]" value="49" id="attrib-14-49" type="checkbox"><label class="attribsCheckbox" for="attrib-14-49">50g</label><br> <input name="id[14][50]" value="50" id="attrib-14-50" type="checkbox"><label class="attribsCheckbox" for="attrib-14-50">75g</label><br> </div> <br class="clearBoth"> </div> <br class="clearBoth"> <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Sugar Bears</h4> <div class="back"> <input name="id[15][51]" value="51" id="attrib-15-51" type="checkbox"><label class="attribsCheckbox" for="attrib-15-51">25g</label><br> <input name="id[15][52]" value="52" id="attrib-15-52" type="checkbox"><label class="attribsCheckbox" for="attrib-15-52">50g</label><br> <input name="id[15][53]" value="53" id="attrib-15-53" type="checkbox"><label class="attribsCheckbox" for="attrib-15-53">75g</label><br> </div> <br class="clearBoth"> </div> <br class="clearBoth"> <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Fruit Cocktail</h4> <div class="back"> <input name="id[16][54]" value="54" id="attrib-16-54" type="checkbox"><label class="attribsCheckbox" for="attrib-16-54">25g</label><br> <input name="id[16][55]" value="55" id="attrib-16-55" type="checkbox"><label class="attribsCheckbox" for="attrib-16-55">50g</label><br> <input name="id[16][59]" value="59" id="attrib-16-59" type="checkbox"><label class="attribsCheckbox" for="attrib-16-59">75g</label><br> </div> <br class="clearBoth"> </div> <br class="clearBoth"> <div class="wrapperAttribsOptions"> <h4 class="optionName back">Organic Jelly Bears</h4> <div class="back"> <input name="id[17][57]" value="57" id="attrib-17-57" type="checkbox"><label class="attribsCheckbox" for="attrib-17-57">25g</label><br> <input name="id[17][58]" value="58" id="attrib-17-58" type="checkbox"><label class="attribsCheckbox" for="attrib-17-58">50g</label><br> <input name="id[17][60]" value="60" id="attrib-17-60" type="checkbox"><label class="attribsCheckbox" for="attrib-17-60">75g</label><br> </div> <br class="clearBoth"> </div> What I need to do is to some how ensure that the product is filled with 75g worth of the other products. Another option may to not use the 'grams' but rather use the 3 compartments that will be filled so 25g = 1, 50g = 2, 75g = 3 etc. Note: Name, Values, Ids are made dynamically by the cart, and I cannot change those as they are used for adding to cart and updating account info etc. PLEASE PLEASE PLEASE if anyone can help, I would really appreciate it. ----------------------------- Jay Hello, Is there any way that I can add a limit for the amount of time that a javascript loader bar stays on screen? The specific loading screen I am using is http://www.fliesen-info-spanien.net/loadbox.php. This loading box actually activates once the page is loaded apparently, but in my instance, it is loading then disappearing in the matter of a second, but I wouldnt mind leaving it up for a couple of seconds, say 3-5. Is there any line of code I can add to do this? Andy Thank you for your help with this. I am newer to JS and appreciate the assistance. I am using iScroll for an image gallery on the iPad. I can place 120 columns equalling 122,880 pixels in width. After that the content fails to display. How can I get additional 180 columns that I have to display? I am new to javascript but am proficient in .net languages. If I have a text file that is structured as follows; -35.889,150.984 -35.578,151.022 -35.449,150.993 I have two questions; 1. How can I read the text in that file into an array? I've tried Code: var file = "X:\ASP.Net\GoogleMaps\GMAP\MarkerCoordinates.txt"; //file:\\X:\ASP.Net\GoogleMaps\GMAP\MarkerCoordinates.txt $.get(file,function(txt) P.S. I tried the commented way above also and that didnt work I also tried using XMLHttprequest like so Code: var txtFile = new XMLHttpRequest(); txtFile.open("GET", "file:\\C:Gmap\test.txt", true); 2. How do you iterate through each line in the array? I'm not sure how to do a for-each in javascript, would be simple in .net Thank you, in advance, for any assistance Here I have a code to redirect a page to one of these three pages. But is there a limit to the amount of websites I can add? Code: <script type="text/javascript"> var urls = new Array(); urls[0] = "http://www.google.com"; urls[1] = "http://www.youtube.com"; urls[2] = "http://www.codingforums.com"; var random = Math.floor(Math.random()*urls.length); window.location = urls[random]; </script> Would I be allowed to have, say, hundreds of thousands of different sites? Or would the script stop working? Thanks. I'm making a graph in Canvas. I plot the grid with ctx.strokeStyle = '#ccc'; I then plot the data lines with ctx.strokeStyle = '#000';, and the GRID color then turns back to '#000' too! The same happens with any color. The same happens with lineWidth. The fillStyle of the labels is not affected. It happens even if I surround the code with save/restore. It happens in both Firefox and Chrome. Has anyone else had this problem? Is there any way around it? I want to limit a textarea to 500 characters. So somebody can't type in more than 500 characters or paste anything with more then 500 characters in the text box. However, if somebody were to enter something into the fields favoritedrink OR to favortefood, then I want the limit to change to 100 characters for the textarea. How can I do that using Javascript? I am using the form code below as an example. Code: <form action=""> <input type="text" name="firstname"><br /> <input type="text" name="lastname"> <textarea rows="2" cols="20" name="description"></textarea> <input type="text" name="favoritefood"> <input type="text" name="favoritedrink"> </form> I need some help for my site and would so much appreciate if somebody can help me with my problem. Thanks so much for any help. Hi, I have this code to get hints (PHP file): Code: <?php include("include/session.php"); $GetNames = "SELECT firstname, lastname, username FROM users"; $GetNamesConnect = $database->query($GetNames); While($row = mysql_fetch_array($GetNamesConnect)) { $a[$row['username']] = $row['firstname'] . " " . $row['lastname']; } //get the q parameter from URL $q=$_GET["q"]; //lookup all hints from array if length of q>0 if (strlen($q) > 0) { $hint=""; for($i=0; $i<count($a); $i++) { if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q)))) { if ($hint=="") { $hint=$a[$i]; } else { $hint=$hint.", ".$a[$i]; } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == "") { $response="no suggestion"; } else { $id = $row['username']; $response= "<a href='profile.php?user=$row['username']'>$hint</a>"; } //output the response echo $response; ?> This is the display part (Javascript/Ajax) Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript"> function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gethint.php?q="+str,true); xmlhttp.send(); } </script> </body> </html> What I want to do it to limit the names suggested to 10, how would I do this? wait... why am i here???
Hi. I have the following line in my HTML file <table class="bz_buglist" cellspacing="0" cellpadding="4" width="100%"> And I need to use javascript to change this line to <table id="main_table" class="bz_buglist" cellspacing="0" cellpadding="4" width="100%"> . I just need to add the ID part. How can I do this? Is there a method of replacing the line, or a way to "add attribute"? thanks! kev. Hi guys. I'm using a jquery plugin called innerfade, which I got from he http://medienfreunde.com/lab/innerfade/ . I've used it to fade few lines of text into each other: Code: <div class="fade"> <p>Line 1 asdfghjkl</p> <p>Line 2 sdasdsafasdgedgr</p> <p>Line 3 ddddddddddddddddddddd</p> </div> So only first line appears on page load, then after few seconds fades into Line 2 etc. Everything works perfect, but there is only one problem - the text is not centered even if it says so in CSS. Since the lines have different lenghts, the shorter the line the more it's aligned to the left. I've added properties for both div and p's - tried all combinations of text-align: center and margin left & right: auto. No joy. But when I remove the script all 3 lines appear centered perfectly. So my question is how do I make them centered? I presume it has to be added in the JS part since it seems to be overriding the CSS. Here is the script's full code: Code: (function($) { $.fn.innerfade = function(options) { return this.each(function() { $.innerfade(this, options); }); }; $.innerfade = function(container, options) { var settings = { 'animationtype': 'fade', 'speed': 'normal', 'type': 'sequence', 'timeout': 2000, 'containerheight': 'auto', 'runningclass': 'innerfade', 'children': null }; if (options) $.extend(settings, options); if (settings.children === null) var elements = $(container).children(); else var elements = $(container).children(settings.children); if (elements.length > 1) { $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass); for (var i = 0; i < elements.length; i++) { $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide(); }; if (settings.type == "sequence") { setTimeout(function() { $.innerfade.next(elements, settings, 1, 0); }, settings.timeout); $(elements[0]).show(); } else if (settings.type == "random") { var last = Math.floor ( Math.random () * ( elements.length ) ); setTimeout(function() { do { current = Math.floor ( Math.random ( ) * ( elements.length ) ); } while (last == current ); $.innerfade.next(elements, settings, current, last); }, settings.timeout); $(elements[last]).show(); } else if ( settings.type == 'random_start' ) { settings.type = 'sequence'; var current = Math.floor ( Math.random () * ( elements.length ) ); setTimeout(function(){ $.innerfade.next(elements, settings, (current + 1) % elements.length, current); }, settings.timeout); $(elements[current]).show(); } else { alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\''); } } }; $.innerfade.next = function(elements, settings, current, last) { if (settings.animationtype == 'slide') { $(elements[last]).slideUp(settings.speed); $(elements[current]).slideDown(settings.speed); } else if (settings.animationtype == 'fade') { $(elements[last]).fadeOut(settings.speed); $(elements[current]).fadeIn(settings.speed, function() { removeFilter($(this)[0]); }); } else alert('Innerfade-animationtype must either be \'slide\' or \'fade\''); if (settings.type == "sequence") { if ((current + 1) < elements.length) { current = current + 1; last = current - 1; } else { current = 0; last = elements.length - 1; } } else if (settings.type == "random") { last = current; while (current == last) current = Math.floor(Math.random() * elements.length); } else alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\''); setTimeout((function() { $.innerfade.next(elements, settings, current, last); }), settings.timeout); }; })(jQuery); // **** remove Opacity-Filter in ie **** function removeFilter(element) { if(element.style.removeAttribute){ element.style.removeAttribute('filter'); } } And call: Code: $(document).ready( function(){ $('.fade').innerfade({ animationtype: 'fade', speed: 750, timeout: 5000, type: 'random', containerheight: '1em' }); }); |