JavaScript - Preserve Whitespace Textarea When Transform To <p>?
Hi, I currently have a <p> where it changes to a textarea when a button is clicked
How do I preserve the whitespace when saving that text to a database and displaying back to a <p>? Similar TutorialsI have a JavaScript application that needs to preserve double quote marks and apostrophes (" and ') that are entered into form fields by the user. The form data is passed through several screens using hidden fields. Right now, apostrophes work because I have the input fields coded as value="". I have not found a way for JavaScript to retrieve the field's value if double quotes are entered by the user. If I change the parameter to value='' (single quotes) then the apostrophes probably won't work. Is there a straightforward way for JavaScript to retrieve the field value containing quotes, so that I can manipulate it into a different string that can be easily passed between HTML pages? i want to transfrom image like the picture below using canvas,it seems simple but i find no way to do , can anyone give me some ideas? ( left side is the source) not sure if this is the right place to ask canvas questions, but if it is, i'm trying to program a game like air hockey (with some twists). it works pretty well now but the table is viewed from overhead, and i would prefer to show the game from the player's perspective, as in the pic, without having to rewrite my existing code. anyone know of any js libraries or formulas which can accomplish this? Hello, I have the code in the annexe wich is working but grossly redondant, clearly, I would like to have only one function toggleEditor(), that would manage the global variables editInstance with a parameter or something equivalent to avoid having 2 twin like functions. Thanks for your suggestions. HJS Annexe : Code: <html> <body> <script src="../flovinax.js" type="text/javascript"></script> <script> var editInstance= null; function toggleEditor1(edtN) { if(editInstance===null) { editInstance = new flovinaxa({fullPanel : true}).panelInstance(edtN); } else { editInstance.removeInstance(edtN); editInstance= null; } } var editInstance2= null; function toggleEditor2(edtN) { if(editInstance2===null) { editInstance2 = new flovinaxa({fullPanel : true}).panelInstance(edtN); } else { editInstance2.removeInstance(edtN); editInstance2= null; } } </script> <div> <textarea style="width: 800px; height: 200px;" id="myArea"></textarea> <br /> <button onClick="toggleEditor1('myArea');">+</button> </div> <div style="clear: both;"></div> <div> <textarea style="width: 800px; height: 200px;" id="myArea2"></textarea> <br /> <button onClick="toggleEditor2('myArea2');">+</button> </div> <div style="clear: both;"></div> </body> </html> Hi, Is it possible that when a webpage loads I can have javascript change the class of a div from: .up { transform: translate(0px,-500px) transition: all 5s ease-in; } to .down { transform: translate(0px,0px) transition: all 5s ease-in; } Essentially I would like a div to move down into place from the top of screen to the middle of screen after the page has loaded. Some thing like this?: Code: <script type="text/javascript"> function transform() { document.getElementById("content").className = "down"; </script> <div id="content" class "up" onload="transform()"> </div> </html> would this work or is there a better way? Adrian. Hi all, are there any tags i can use that will tell the parser somehow to ignore whitespace in the HTML section? The html and jave script is pasted into a custom page widget that can interpret the code, the problem is that my indentation and general coding formatting as i am writing it in my editor is also somehow being translated in the rendering - it seems mostly to be the linebreaks, in fact i would say it is only the line breaks, so the layout is appearing spread across too many lines for example, instead of neat and tight together, which is what i see in a browser. I realise this is probably the parser implementation at the application end, but can i get around this directly myself? I cannot use xml or xslt to get around this, i can only write direct html or java into this custom widget. Basically I have this: function semaphore(phrase) { var len = phrase.length; var str1 = ""; for (var i=0;i<len;i++) { if(phrase[i]=" ") { phrase[i] = "interval"; } var str = "images/semaphore/" + phrase[i] + ".gif"; str1 = str1 + "<img src='" + str + "'>"; } return str1; } so if phrase = i love coding forums I want all the spaces to be replaced with the text "interval" Thanks Danny 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 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) 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 Hey all, I have a script that limit characters and lines entered by users in a textarea.. i want instead of throwing that alert message to jump to the next line and the user can continue writing, here is the script: Code: <script type="text/javascript"> var alert_title='Input Restriction'; function limitTextarea(el,maxLines,maxChar){ if(!el.x) { el.x=uniqueInt(); el.onblur=function(){clearInterval(window['int'+el.x])} } window['int'+el.x]=setInterval(function(){ var lines=el.value.replace(/\r/g,'').split('\n'), i=lines.length, lines_removed, char_removed; if(maxLines&&i>maxLines){ alert('You can not enter\nmore than '+maxLines+' lines'); lines=lines.slice(0,maxLines); lines_removed=1 } if(maxChar){ i=lines.length; while(i-->0)if(lines[i].length>maxChar){ lines[i]=lines[i].slice(0,maxChar); char_removed=1 } if(char_removed) alert('You can not enter more\nthan '+maxChar+' characters per line') } if(char_removed||lines_removed) el.value=lines.join('\n') },50); } function uniqueInt(){ var num,maxNum=100000; if(!uniqueInt.a||maxNum<=uniqueInt.a.length)uniqueInt.a=[]; do num=Math.ceil(Math.random()*maxNum); while(uniqueInt.a.hasMember(num)) uniqueInt.a[uniqueInt.a.length]=num; return num } Array.prototype.hasMember=function(testItem){ var i=this.length; while(i-->0)if(testItem==this[i])return 1; return 0 }; </script> The HTML Code: <textarea onFocus="limitTextarea(this,5,40)" wrap="soft"></textarea> please help! 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> 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> 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:-) I can write all kinds of stuff, but one thing is failing me, and is extremely frustrating. document.getElementById('fakeid').value; which is my least preferred option, won't even work on this text area. Either will: Code: var objElem = document.getElementById(strId); var objElem = objElem.getElementsByTagName('textarea'); var strComment = objElem[0].value; It will work fine in IE but will not in Firefox. I cannot understand why as I've done this many times before. The code it is using is: Code: <div id="commentAdd"><h3 id="commentHeader"><a href="javascript:;" onclick="func_toggle_visibility("commentAddContent");return false;">Add a comment</a></h3> <div class="contentnopadding" id="commentAddContent" style="display:block;"> <form id="formCommentAdd"> <div class="comleft"> <table> <tr><td><span class="subhead">Add Comment:</span></td><td><textarea id="fakeid" rows="3" cols="35"></textarea></td></tr> </table> </div> <div class="content"> <input id="commentAddSubmit" type="button" value="Submit Comment" onclick="commentInitAjax(this.id,'comment','1',false);"> </div> </form></div></div><br><br> <div class="contentnopadding"></div> hitting submit triggers that function (which i haven't pasted all of it, just the necessary parts). I have an alert right after where i assign the value, but it does not work in FF. Please help, it's giving me grief (if it helps, the HTML is written by javascript, but i can't see how it would have any effect). I found a script that is perfect for my need but it is written for forms textareas and I can seem to get it to work textareas that are not wrapped in form. Code: Code: <script>function insertAtCursor(sTag,eTag) { var obj = document.form.message; var strPos; var ie_strPos; var oSel; obj.focus(); strPos += sTag.length + eTag.length; ie_strPos += sTag.length + eTag.length; if (document.selection && document.selection.createRange) { // Internet Explorer oSel = document.selection.createRange(); if (oSel.parentElement() == obj) { oSel.text = sTag + oSel.text + eTag; ie_strPos += oSel.text.length; } oSel.moveStart ('character', ie_strPos); oSel.moveEnd ('character', 0); oSel.select (); } else if (typeof(obj) != "undefined") { // Firefox var longueur = parseInt(obj.value.length); var selStart = obj.selectionStart; var selEnd = obj.selectionEnd; obj.value = obj.value.substring(0,selStart) + sTag + obj.value.substring(selStart,selEnd) + eTag + obj.value.substring(selEnd,longueur); strPos += txtarea.value.substring(selStart,selEnd).length; obj.selectionStart = strPos; obj.selectionEnd = strPos; obj.focus (); } else obj.value += sTag + eTag; obj.focus(); } </script> <button onclick="insertAtCursor('[blah]','[/blah]')">Test</button> <form method="post" name="form" action=""> <textarea name="message" cols="50" rows="10"></textarea> </form> My textarea: Code: <textarea id="new_topic_text" class="new-topic-subject-text elastic" style="overflow: hidden;"></textarea> 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 Hi, Nothing will display in my textarea after pressing an input number which have to seen on the display. The code is from a simple calculator <form action="#" method="get" onsubmit="return false"> <p> <textarea disabled="disabled"></textarea> </p> <div id="calculatorButtons"> <p> <button onclick="calculatorNumber(1)">1</button> <button onclick="calculatorNumber(2)">2</button> <button onclick="calculatorNumber(3)">3</button> <button onclick="calculatorOp('+')">+</button> </p> <p> <button onclick="calculatorNumber(4)">4</button> <button onclick="calculatorNumber(5)">5</button> <button onclick="calculatorNumber(6)">6</button> <button onclick="calculatorOp('-')">-</button> </p> <p> <button onclick="calculatorNumber(7)">7</button> <button onclick="calculatorNumber(8)">8</button> <button onclick="calculatorNumber(9)">9</button> <button onclick="calculatorOp('*')">*</button> </p> <p> <button onclick="calculatorNumber(0)">0</button> <button onclick="calculatorOp(',')">,</button> <button onclick="calculatorClear()">Clear</button> <button onclick="calculatorCalculate()">Calc</button> </p> </div> </form> function calculatorNumber(i) { document.form.getElementById('textarea').innerHTML = i; } What is the right way to refer to the textarea? 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> |