jquery - I'm tyring to use a script to undo ALL CAPS in my text area -


i have textarea receives inputs in caps, fine users. users need text represented in normalized fasion - first letter of each sentence capitalized , rest lowercase.

i tried adapt suggestions other threads, somethings missing. please!

body

<form>         <input value="select all" onclick="javascript:this.form.finaltext.focus();this.form.finaltext.select();"  type="button">         <input value="clear all" onclick="this.form.finaltext.value=''" type="button">         <input value="normalize text" type="button"  id="normalize">         <a href="#" id="copy-textarea"><input type=button value="copy clipboard"></a><br>         <br>         <textarea id="finaltext" cols="80" rows="50"> </textarea>         </form> 

script

$(window).load(function(){ $('#normalize').click(function capitalizesentences(){  var captext = $("#finaltext").val(); captext = captext.tolowercase();  captext = captext.replace(/\.\n/g,".[-<br>-]. "); captext = captext.replace(/\.\s\n/g,". [-<br>-]. "); var wordsplit = '. ';  var wordarray = captext.split(wordsplit);  var numwords = wordarray.length;  for(x=0;x<numwords;x++) {      wordarray[x] = wordarray[x].replace(wordarray[x].charat(0),wordarray[x].charat(0).touppercase());          if(x==0) {             captext = wordarray[x]+". ";         }else if(x != numwords -1){             captext = captext+wordarray[x]+". ";         }else if(x == numwords -1){             captext = captext+wordarray[x];         }                } captext = captext.replace(/\[-<br>-\]\.\s/g,"\n"); captext = captext.replace(/\si\s/g," ");   $("#finaltext").val(captext); }); }); 

update 1 script works.

new question how can manipulate logic in .replace brackets following situation:

the text area want allow "normalization" in following format:

  • text1
  • text2
  • text3

with dash, space , caps text. .replace logic seems first character in string, treat each line (starting dash) separately , leave first letter thereafter capitalized.

i'm taking suggestion below , posting corrected code solved click problem - credit ross:

i needed wrap script in window.load function include function in dom after rendering.

$(window).load(function(){ ...script...  })); 

Comments