JavaScript - Newline From Html Into Textarea
if I have this inside TD tag
Code: a<br>b what should I write instead ??? to reproduce new line in textarea Code: result = result.replace(/<br>/ig,"???") Similar TutorialsHi, I have a textarea element and I fill it with text. But I want to insert newlines to seperate some of the words in the textarea. I tried to use '\r' or '\n' or '\r\n', but none of them works. Code: var textArea = document.createElement('textarea'); textArea.value = 'good' + '\n' + 'morning'; The newline has no effect, it still show 'good morning'. Why? And also, I am going to write these words in the textarea into database and later retrieve them back from database to another textarea, should I keep the newline characters or is it better use some other delimiter? Many thanks. If I have a javascript var in a webpage(html form textarea VALUE - yui) that contains html code, and want to appear it, in confirmformpage.php, then how to transfer it...? is it really needed go via PHP ...? and ofcourse use innerHTML to write it....yes I usually use an intermitened processform.php script. http://developer.yahoo.com/yui/editor Hi, my javascript does not working after I retrieve a record that contains square symbol in the database. The square symbol should be a newline in a textarea. This is how the record "looks" in the table: Actually, I am inserting the record using ASP and the value with square symbol is the value from a textarea with newline/enter. After that I retrieve the value using ASP and pass it to javascript and then the page is not working. If I retrieve other record which contain no square symbol then the script is working. Please help on this, appreciates! Ok I have a textarea field that is validated by Js, this textarea can and will contain the newline character Code: \n so I validate in JS Code: if(textareaname.value.length < 200) this hten goes through to my php where i also check before I place in to the Database using MYSQL Code: if( strlen($_POST['textareaname']) < 200 ) but my php is giving me a different string length from my javascript. It looks as if Javascript is counting a newline as 1 character and php is treating it as 2. I have checked my slashes, I have used various REgex to check these data amounts. I have also Googled around and there doesnt seem much around. Any ideas? Any suggestions as to how I can make php and javascript treat a newline as the same amount of characters? Thanks in advance. I am trying to replace all newline characters with <br /> tags. The following two javascript functions that I've found, work in Firefox but do not work in Internet Explorer (I have version 7 installed on my machine). I would really appreciate any pointers on how to get this done. Thank you! Joe PS: I am using jQuery to call these functions. And this is how my JSP page looks like. Code: <html> <head> <title>New Line Replacement</title> <script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function replaceNewLine(myString) { var regX = /\r\n|\r|\n/g; var replaceString = '<br />'; return myString.replace(regX, replaceString); } $().ready(function(){ $(".replace-text").each(function(i) { var sBody = $(this).html(); $(this).html(replaceNewLine(sBody)); }); }); /* function nl2br(text){ text = escape(text); var re_nlchar; if(text.indexOf('%0D%0A') > -1){ re_nlchar = /%0D%0A/g ; }else if(text.indexOf('%0A') > -1){ re_nlchar = /%0A/g ; }else if(text.indexOf('%0D') > -1){ re_nlchar = /%0D/g ; } return unescape( text.replace(re_nlchar,'<br />') ); } */ </script> </head> <body> <div class="replace-text">${model.paraOne}</div> <div class="replace-text">${model.paraTwo}</div> </body> </html> I've done a bit of searching and I can't find the answer to my question. I'm working on a website for my business. I have some basic knowledge of coding but I'm mostly a code cobbler. I find various pieces and put it together and hope it works so take it easy on me. I have some code to display products on my site. It works fine. We just have a lot of products and for me to add each one by hand was getting ridiculous. I finally had the bright idea to use Javascript to generate the code for me and then copy it back into my actual HTML page. Last night I wrote the code below. It works perfectly except I have to constantly "View Source" in order to get the code. I was hoping to cut down on a step or two and have the code go into a TextArea. From there I can just select it and copy it into the HTML file. It should make things a little quicker and most importantly easier. Maybe after that I'll try to figure out how to write function to select everything in the TextArea and copy it to my clipboard. That would make things even faster. Any help? 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=iso-8859-1" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> function calc (form) { var images = form.images.value; var imagesArray = images.split("\n"); var linebreak = "<br />"; var i=0; var j=0; var a=0; while(i < imagesArray.length) { if(j==0) { document.write (" <!-- -------------------------------------------- -->\n"); document.write (" <div id=\"cols3-top\"></div>\n"); document.write (" <div id=\"cols3\" class=\"box\">\n"); } a++; if(j/2!=1) { if(a==imagesArray.length) { document.write ("\n <!-- ---------------- -->\n\n"); document.write (" <div class=\"col last\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); document.write (" </div>\n"); document.write (" <div id=\"cols3-bottom\"></div>\n"); document.write (" <!-- /Columns End Here -->\n\n\n"); break; } else { document.write ("\n <!-- ---------------- -->\n"); document.write (" <div class=\"col\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); i++; j++; } } else { document.write ("\n <!-- ---------------- -->\n\n"); document.write (" <div class=\"col last\">\n"); document.write (" <h3>Header</h3>\n"); document.write (" <p class=\"nom t-center\">\n"); document.write (" <a href=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" class=\"nivoZoom center\"><img src=\"../../product_imgs/resins/pdu/54xxxgs/" + imagesArray[i] + ".jpg\" alt=\"" + imagesArray[i] +"\" height=\"200px\" /></a></p>"); document.write (" <!-- /col-text -->\n"); document.write (" <div class=\"col-itemnum\">PDU: " + imagesArray[i] + "</div>\n"); document.write (" </div>\n"); document.write (" <!-- /col -->\n"); document.write (" <hr class=\"noscreen\" />\n"); document.write (" </div>\n"); document.write (" <div id=\"cols3-bottom\"></div>\n"); document.write (" <!-- /Columns End Here -->\n\n\n"); i++; j=0; } } document.close(); } </script> </head> <body> <div style="width:960px; margin:0 auto;"> <form name="myform" method="get" action=""> <textarea label="Image Names:"name="images" cols="30" rows="15" onclick="this.value=''" ></textarea> <p> <label> <input type="button" name="calculate" value="Calculate" onClick="calc(this.form)"/> </label> </p> </form> </div> </body> </html> hi, I have some HTML to edit in my database, in my back end administration I have it in a textarea but when I go to edit it, it all messes up and lots of '/' area added, see below: Code: Site Design by: <a href=\\\\\\\"http://www.jbiddulph.com\\\\\\\" target=\\\\\\\"_blank\\\\\\\" title=\\\\\\\"John Biddulph - Web Development\\\\\\\">jbiddulph.com</a> php code Code: <p> <label>Site Design by</label> <textarea class="text-input small-input" name="SiteDesignby"><?php echo $row1['SiteDesignby'] ?></textarea> </p> Can anyone help please? 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! Hi all, I'm loading external xml and displaying specific tagged elements in a textarea. It works fine in IE because I can turn the variable object into text with a simple object.text property, but in Firefox (using the serializeToString method), the object appears in my textarea tags and all. The code looks something like this (this is just a dummy script - imagine the xml is already loaded into the object xmlDoc ): Code: function writePage(){ document.write('<textarea name="inputText">'+myText+'</textarea>'); } function xmlIsLoaded(){ if(window.ActiveXObject){ //tests for IE myText = xmlDoc.getElementsByTagName("desiredTag")[0].text; } else { //tests for FF myText = (new XMLSerializer()).serializeToString(xmlDoc.getElementsByTagName("desiredTag")[0]); } writePage(); } What am I missing here? I've tried toString, textContent, innerText, childNodes - just about everything I can think of to get just the text w/o the tags from the xml for the FF version. Any thoughts? ~gyz Hello there . Here is my simple code Quote: <html> <head> <script> function addText(){ document.getElementById("textarea").value+=document.getElementById("text").value+'\n'; document.getElementById("text").value=""; document.getElementById("text").onblur=document.getElementById("text").value=" Your Message..."; } </script> <style> #textarea{background-color:#F3F3F3; } </style> </head> <body> <form> <TEXTAREA id="textarea" COLS="80" ROWS="20" ></TEXTAREA><br/><br/> <input type="text" id="text" name="text" value=" Your Message..." onclick="this.value=''" size="96"> <input type="button" value="Send" name="submit" onclick="addText()"> </form> </body> </html> My problem is I dont know what to do iorder to make my send button to push the text entered in the text field from bottom to the top (not from the top to the bottom) Is 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? I'm having trouble with the way my textarea is displaying text when it's submitted. It always comes out as one line of text instead of the way a user has entered it. Here's my code. Code: <textarea name="info" value="" rows="7" cols="55"> Enter Your Personal Information Here </textarea><br /><br /> That is then called to a function which displays it in a new page. Code: <script> function buildResume() { resInfo = document.myResume.info.value flyWindow = window.open() flyWindow.document.write("Personal Information " + resInfo); } </script> If any knows how I could fix this it'd really help. I've tried using the pre element and wrap property with no luck. I sell products on amazon. and ASINs are Amazon Identifiers for products. So If I want to check out my product pages I have to go to "www.amazon.co.uk/dp/ "I have to put an ASIN here" . If I can put everything together in the text box and hit go it should take me to the first page(first ASIN). Here is a sample ASIN B004Z2QORW I have the code below but I somehow cant get it to work. Please help. I haven't assigned anything to the go button. I will put a list of ASINs in the text area and the iframe should concatenate the value from a row to the hardcoded URL and when I click next it should concatenate the value from the next row; when I click previous the value from the previous row. Code: <HTML> <Head> <H1 align="center">Detail Page Lookup using ASINs</H1> </head> <body> <textarea rows="10" cols="20" value=""> ASINs here </textarea> <button id="go">Go</button> <button id="prev" align="right">Previous</button> <button id="next" align="right">Next</button> <br/> <iframe id="myframe" src="http://www.amazon.co.uk/dp/" height="100%" width="100%"> <p>Your browser does not support iframes.</p> </iframe> <script>var domain='http://www.amazon.co.uk/dp/'; $('#prev, #next').on('click', function(e) { var Myval = $('textarea').val().split('\n'), now = $('#myframe').attr('src').replace(domain, ''); if (Myval.indexOf(now)==-1) { var src=domain+Myval[0]; }else{ var p = Myval.indexOf(now)!==0 ? Myval.indexOf(now)-1 : Myval.length-1, n = Myval.indexOf(now)==(Myval.length-1) ? 0 : Myval.indexOf(now)+1, src = e.target.id=='next' ? domain+Myval[n] : domain+Myval[p]; } $("#myframe").attr('src', src); console.log(src); }); ? </script> </body> </HTML> so I am creating a silly word ;irate word interpreter page, and I need some logic behind how to add text to a textarea each time I click on a button. Each time the user clicks on the button, the value is inserted into the text area. You should be able to click on multiple buttons to add to the last text that appears. Then I have a delete translation button when I want to clear the textarea field. A good example would be if the user clicks on the button with the value "sir", than "matey" will appear in the textarea. Now, if the user clicks on the button with the value "your", then "yer" will come up after matey. It's like creating a sentence on your own, and then deleting it when your done. Code: <body> <div id="page"> <div> <img style="float:left" src="slue.gif" width="205" height="190" alt=""> <div> <h1>Pirate Translator</h1> <p>Simply click on the buttons to translate words and/or phrases from English to pirate talk</p> </div> </div><br /> <hr /> <form name="pirate"> <div> <fieldset> <legend><b>Greetings:</b></legend> <input type="button" id="greeting" value="hello" /> <input type="button" id="greeting" value="pardon me" /> <input type="button" id="greeting" value="excuse me" /> <input type="button" id="greeting" value="" /> <input type="button" id="greeting" value="" /> <input type="button" id="greeting" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>People:</b></legend> <input type="button" id="people" value="sir" /> <input type="button" id="people" value="madam" /> <input type="button" id="people" value="miss" /> <input type="button" id="people" value="stranger" /> <input type="button" id="people" value="officer" /> <input type="button" id="people" value="" /> <input type="button" id="people" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>Questions:</b></legend> <input type="button" id="question" value="where is" /> <input type="button" id="question" value="can you help me" /> <input type="button" id="question" value="is that" /> <input type="button" id="question" value="how far is it to" /> <input type="button" id="question" value="" /> <input type="button" id="question" value="" /> <input type="button" id="question" value="" /> <input type="button" id="question" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>Articles:</b></legend> <input type="button" id="article" value="the" /> <input type="button" id="article" value="my" /> <input type="button" id="article" value="your" /> <input type="button" id="article" value="" /> <input type="button" id="article" value="" /> <input type="button" id="article" value="" /> <input type="button" id="article" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>Adjectives:</b></legend> <input type="button" id="adject" value="old" /> <input type="button" id="adject" value="attractiv" /> <input type="button" id="adject" value="happy" /> <input type="button" id="adject" value="" /> <input type="button" id="adject" value="" /> <input type="button" id="adject" value="" /> <input type="button" id="adject" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>Places:</b></legend> <input type="button" id="places" value="restroom" /> <input type="button" id="places" value="restaurant" /> <input type="button" id="places" value="mall" /> <input type="button" id="places" value="hotel" /> <input type="button" id="places" value="pub" /> <input type="button" id="places" value="" /> <input type="button" id="places" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>Desires:</b></legend> <input type="button" id="desire" value="I would like to" /> <input type="button" id="desire" value="I desire" /> <input type="button" id="desire" value="I wish I knew how to" /> <input type="button" id="desire" value="my mother told me to" /> <input type="button" id="desire" value="my campanion tells me to" /> <input type="button" id="desire" value="" /> <input type="button" id="desire" value="" /> </fieldset> </div> <div> <fieldset> <legend><b>Actions:</b></legend> <input type="button" id="action" value="find" /> <input type="button" id="action" value="take a nap" /> <input type="button" id="action" value="kill" /> <input type="button" id="action" value="hurt you" /> <input type="button" id="action" value="beat you up" /> <input type="button" id="action" value="go to the bathroom" /> <input type="button" id="action" value="" /> </fieldset> </div> <div> <p id="output"><textarea id="task_list" rows="5" cols="130"></textarea></p> <p id="output"><input type="button" id="" value="Delete Traslations" /></p> </div> </div> </form> <script src="js/translate.js"></script> </body> </html> Hi guys, My brain is not working. May be I need a coffee break. I need your expertise. Below is the code holding the textarea. Look for the element with the id : themessage Code: <table width="100%" border="0"> <tr><td rowspan="4"><input type="button" name="send_email" id="send_email" style="height:50px; width:100px;" value="SEND" onClick="return err_check();" /></td><td><span class="que">From : </span></td><td colspan="3"><?php echo $from_email; ?><input type="hidden" name="from_mail" id="from_mail" value="<?php echo $from_email;?>"/><input type="hidden" name="camp_id" id="camp_id" value="<?php echo $camp_id;?>"/></td></tr> <tr><td><span class="que">To : </span></td><td colspan="3"><input name="to_email" id="to_email" style="width:250px;" /></td></tr> <tr><td><span class="que">CC : </span></td><td colspan="3"><input name="cc_email" id="cc_email" style="width:250px;"/></td></tr> <tr><td><span class="que">Subject : </span></td><td colspan="3"><input style="width:300px;" name="subject" id="subject" /></td></tr> <tr><td rowspan="1" colspan="2"> </td><td><input type="checkbox" name="ori_pdf" id="ori_pdf" /> PDF Quotation</td><td> </td><td> </td></tr><tr><td colspan="2"><span class="que">Credit Application</span></td><td><input type="checkbox" name="corporate" id="corporate"/>Corporate</td><td><input type="checkbox" name="individual" id="individual" />Individual</td><td><input type="checkbox" name="cash" id="cash" />Cash Account</td> </tr> <tr> <td colspan="2" rowspan="3"></td><td><input type="checkbox" name="tabloid" id="tabloid" />Tabloid Example</td> <td><input type="checkbox" name="broadsheet" id="broadsheet" />Broadsheet Example</td></tr> <tr><td><input type="checkbox" name="colmt" id="colmt" />Column Sizes Tabloid</td> <td><input type="checkbox" name="colmb" id="colmb" />Column Sizes Broadsheet</td></tr> <tr><td><input type="checkbox" name="maps" id="maps" />Maps / Distribution</td><td colspan="2" align="right">External Attachments <input id="upload_file" name="upload_file" type="file"/> </td></tr> <tr><td colspan="2"><span class="que">Message :</span></td><td colspan="3"> <textarea id="themessage" name="themessage" rows="15" cols="80" style="width: 100%"> </textarea> </td></tr> </table> Now on a button click, I'm trying to pass some values which one of them happens to be what ever that is entered in the textarea. For some reason, the stupid JS is not reading. But I think it is me that is stupid, not JS. Below is the code i'm running to get the value. Code: var message = document.getElementById('themessage').value; alert(message); The alert simply returns blank. There is an alert, but no value even where there is text in the text area. Can someone please shed some light on this. pretty please I'm making this expanabel textarea which works fine, but... If I set a predefined numbers of rows, when start typing it jumps back (schrinks) into 2 rows... How do I avoid this? Code: <script> function checkRows(textArea){ if (navigator.appName.indexOf("Microsoft Internet Explorer") == 0) { textArea.style.overflow = 'visible'; return; } while ( textArea.rows > 4 && textArea.scrollHeight < textArea.offsetHeight ){ textArea.rows--; } while (textArea.scrollHeight > textArea.offsetHeight) { textArea.rows++; } return; } </script> <textarea style="overflow:hidden;" onkeyup="checkRows(this)" rows="4">Some Test Text</textarea> Thanks in advance:-) hi I am trying to create a textarea. There is a default text inside textarea. so when user clicks inside textarea then submit button appears and default text disappears and when user clicks somewhere else or outside textarea then it gets back to original state i.e, default text appears back and submit button disappears. here is what i did sofar. in this code when i click inside textarea then submit button does appear but text does not erase and when i click outside then button remains in sight. 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> <style> #submit { visibility: hidden; } </style> </head> <body> <form> <label>Message:</label> <textarea name="message" id="message" rows="5" cols="30">write message here!</textarea><br /> <input type="button" name="submit" id="submit" value="submit" /> </form> </body> <script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script> <script> var flag = false; $(document).ready(function () { $('#message').click(function () { flag = true; $('#submit').css('visibility','visible'); if(flag == true) { //alert(flag); var msg = $('#message').val(); //alert(msg); msg = ""; //alert(msg); } }); }); </script> </html> is it possible to make a textarea resize with text? so if e.g the text overflows, the text-area is automatically resized so that there's no scrolling? It needs to resize automatically as the user is typing (more or less), he/she shouldn;t click on any buttons to resize it
hi i am new to javascript. i want to make a form where a textarea, some buttons like bold,italic,link etc will be availablw. when user selecet some text from textarea and click bold button then one openig and closing tag will be added like this [sb]abc[/sb] how can i do this using javascript. any idea? pls. help |