Note that there are some explanatory texts on larger screens.

plurals
  1. POLimiting character in textbox input
    primarykey
    data
    text
    <p>please be nice. I'm trying to create a page which sets limit and cut the excess (from the specified limit). Example: Limit is 3. then, I'll input abc if I input d it must say that its limit is reached and the abc will remain. My problem is that it just delete my previous input and make new inputs. Hoping for your great cooperation. Thanks.</p> <pre><code> &lt;html&gt; &lt;script type="text/javascript"&gt; function disable_btn_limit(btn_name) { /* this function is used to disable and enable buttons and textbox*/ if(btn_name == "btn_limit") { document.getElementById("btn_limit").disabled = true; document.getElementById("ctr_limit_txt").disabled = true; document.getElementById("btn_edit_limit").disabled = false; } if(btn_name == "btn_edit_limit") { document.getElementById("btn_limit").disabled = false; document.getElementById("ctr_limit_txt").disabled = false; document.getElementById("btn_edit_limit").disabled = true; } } function check_content(txtarea_content) { /*This function is used to check the content*/ // initialize an array var txtArr = new Array(); //array assignment //.split(delimiter) function of JS is used to separate //values according to groups; delimiter can be ;,| and etc txtArr = txtarea_content.split(""); var newcontent = ""; var momo = new Array(); var trimmedcontent = ""; var re = 0; var etoits; var etoits2; //for..in is a looping statement for Arrays in JS. This is similar to foreach in C# //Syntax: for(index in arr_containter) {} for(ind_val in txtArr) { var bool_check = check_if_Number(txtArr[ind_val]) if(bool_check == true) { //DO NOTHING } else { //trim_content(newcontent); newcontent += txtArr[ind_val]; momo[ind_val] = txtArr[ind_val]; } } var isapa = new Array(); var s; re = trim_content(newcontent); for(var x = 0; x &lt; re - 1; x++){ document.getElementById("txtarea_content").value += momo[x]; document.getElementById("txtarea_content").value = ""; } } function trim_content(ContentVal) { //This function is used to determine length of content //parseInt(value) is used to change String values to Integer data types. //Please note that all value coming from diplay are all in String data Type var limit_char =parseInt(document.getElementById("ctr_limit_txt").value); var eto; if(ContentVal.length &gt; (limit_char-1)) { alert("Length is greater than the value specified above: " +limit_char); eto = limit_char ; etoits = document.getElementById("txtarea_content").value; //document.getElementById("txtarea_content").value = "etoits"; return eto; //for(var me = 0; me &lt; limit_char; me++) //{document.getElementById("txtarea_content").value = "";} } return 0; } function check_if_Number(ContentVal) { //This function is used to check if a value is a number or not //isNaN, case sensitive, JS function used to determine if the values are //numbers or not. TRUE = not a number, FALSE = number if(isNaN(ContentVal)) { return false; } else { alert("Input characters only!"); return true; } } &lt;/script&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="text" name="ctr_limit_txt" id="ctr_limit_txt"/&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="button" name="btn_limit" id="btn_limit" value="Set Limit" onClick="javascript:disable_btn_limit('btn_limit');"/&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="button" name="btn_edit_limit" id="btn_edit_limit" value="Edit Limit" disabled="true" onClick="javascript:disable_btn_limit('btn_edit_limit');"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;textarea name="txtarea_content" id="txtarea_content" onKeyPress="javascript:check_content(this.value);"&gt;&lt;/textarea&gt; &lt;br&gt; *Please note that you cannot include &lt;br&gt;numbers inside the text area &lt;/td&gt; &lt;/tr&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload