JavaScript - Js To Fix Special Chars In <textarea> Does Not Work
Hi I have downloaded the code to allow special html characters in <textarea> be replaced with the actual code so it does not cause problem when the text is submitted into the database. For example '>' to be replaced with '>' So for a string ' 3 > 2' I expect to be replaced with '3 > 2; in the text box. However it does not work.
I put in the alert statements and it shows that the js function is being invoked, but after the function is done, the special characters in the text box remain the same. Can someone help? <html> <header> </header> <body> <script language="javascript"> function html2entities(){ var re=/[(<>"'&]/g for (i=0; i<arguments.length; i++) alert("check char"+ arguments[i].value); arguments[i].value=arguments[i].value.replace(re, function(m){return replacechar(m)}) } function replacechar(match){ if (match=="<") return "<" else if (match==">") return ">" else if (match=="\"") return """ else if (match=="'") return "'" else if (match=="&") return "&" } </script> <form> Data 1 <textarea name="data1" style="width: 400px; height: 100px"></textarea><br /> <input type="button" onClick="html2entities(this.form.data1)" value="Convert special chars to entities"> </form> </body> </html> Similar TutorialsI am trying to make a very simple form so a user can enter some text then be redirected to a page that uses that text in the URL. So far I have this working using window.open but the ? and & in the URL show up as & # 0 3 8 ; here is the code in the body; Code: <script type="text/javascript"> /* <![CDATA[ */ function orderBlog() { var subDomain = document.blogDomain.domainEntered.value; window.open("http://mydomain.com/portal/cart.php?=add&pid=15&domainoption=subdomain&sld=" + subDomain + ""); } /* ]]> */ </script> <form name='blogDomain' onsubmit="orderBlog();"> <input type='text' name='domainEntered' size='60' style='width:100px;' /> .mydomain.com <input type="submit" value="Get Your Site!" /> </form> but for some reason that goes to the URL mydomain.com/portal/cart.php & # 0 3 8 ; =add & # 0 3 8 ; pid=15 & # 0 3 8 ; domainoption=subdomain & # 0 3 8 ; sld=XXXXXXXX when using firfox, ie7 works fine hi, I would like to change my validation page so that a user cannot use special characters in the form, here is my code below Code: jQuery("#full_name").validate({ expression: "if (VAL) return true; else return false;", message: "Please enter your name" }); jQuery("#name").validate({ expression: "if (VAL.match(/^[^\\W][a-zA-Z\\_\\-\\.]+([a-zA-Z\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;", message: "Please enter your name" }); I want to remove special characters in form fields. It should be automatic. I have a name filed where user entering text and i not want special characters, it should remove automatic. something like this i need, Code: onkeyup="javascript:this.value=this.value.replace(/[^0-9]/g, '');" here, all non-digits get removed automatic. Need help. I am using the following code to pop up a help balloon when the mouse hovers over an input element: Code: function eltMouseOver() { // if there is already a help division displayed, hide it if (helpDiv) { helpDiv.style.display = 'none'; helpDiv = null; } // in some cases the mouseover event is against the table cell // containing the input element. Locate the first element node // under the cell to display help for if (this.nodeName == 'TD') { // mouseover defined for the cell containing the element for (var i = 0; i < this.childNodes.length; i++) { // loop through children of this var cNode = this.childNodes[i]; if (cNode.nodeType == 1) { // element helpElt = cNode; break; } // element } // loop through children of this } // mouseover defined for the cell containing the element else helpElt = this; helpDelayTimer = setTimeout(popupHelp, 2000); } // eltMouseOver function popupHelp() { displayHelp(helpElt); } // popupHelp function displayHelp(elt) { var helpDivName = ""; try { // the help division name may be supplied by an explicit private // attribute "helpDiv" if (elt.helpDiv) helpDivName = elt.helpDiv; else if (elt.name && elt.name.length > 0) { // element has a name if (elt.name.substring(elt.name.length - 2) == "[]") { // multiple selection helpDivName = elt.name.substring(0, elt.name.length - 2); } // multiple selection else { // ordinary element helpDivName = elt.name; } // ordinary element } // element has a name else { // try id attribute helpDivName = elt.id; } // try id attribute } catch(e) { // exception thrown trying to get help division name var attrList = ""; for(attr in elt) attrList += attr + ", "; alert("keyDown: exception=" + e + ", elt=" + attrList); } // exception thrown trying to get help division name // to ensure unique id values, the supplied name is // prefixed with "Help". However some forms have not been // updated to use this convention helpDiv = document.getElementById("Help" + helpDivName); if (!helpDiv) { // first choice not found // strip off trailing decimal digits if any representing // a row number for (var l = helpDivName.length; l > 1; l--) { // find last non-numeric character if (helpDivName[l - 1] < '0' || helpDivName[l - 1] > '9') { // non-digit helpDivName = helpDivName.substr(0, l); helpDiv = document.getElementById("Help" + helpDivName); break; } // non-digit } // find last non-numeric character // if cannot find division with name prefixed with 'Help' // then try without if (!helpDiv) helpDiv = document.getElementById(helpDivName); } // first choice not found if (helpDiv && (helpDiv != elt)) { // have a help division to display // If presentation style requires capitalization, // report it in help var textTransform = ""; if (elt.currentStyle) { // browser supports IE API textTransform = elt.currentStyle.textTransform; } // browser supports IE API else if (window.getComputedStyle) { // browser supports W3C API var style = window.getComputedStyle(elt, null); textTransform = style.textTransform; } // browser supports W3C API if (textTransform == "capitalize") { if (!helpDiv.capitalized) { // add text to help helpDiv.appendChild(document.createTextNode( "Text entered in this field is automatically capitalized." )); helpDiv.capitalized = true; } } // if the field has automatic abbreviation expansion // describe it addHelpAbbrs(helpDiv, elt.abbrTbl); // display the help balloon in an appropriate place on the page var cell = elt.parentNode; var row = cell.parentNode; var tbody = row.parentNode; var table = tbody.parentNode; //alert("helpDiv=" + tagToString(helpDiv)); helpDiv.style.left = Math.max(Math.min(getOffsetLeft(elt) - 50, table.offsetWidth - Math.floor(window.innerWidth/2)), 2) + 'px'; helpDiv.style.top = (getOffsetTop(elt) + 20) + 'px'; helpDiv.style.display = 'block'; // so key strokes in balloon will close window helpDiv.onkeydown = keyDown; } // have a help division to display else alert("Cannot find <div id='Help" + helpDivName + "'>"); } // displayHelp I activate support for this on every element in the page by means of the following code in the onload handler: Code: for(var i = 0; i < document.forms.length; i++) { var form = document.forms[i]; for(var j = 0; j < form.elements.length; j++) { var element = form.elements[j]; // pop up help balloon if the mouse hovers over a field // for more than 2 seconds if (element.parentNode.nodeName == 'TD') { // set mouseover on containing cell element.parentNode.onmouseover = eltMouseOver; element.parentNode.onmouseout = eltMouseOut; } // set mouseover on containing cell else { // set mouseover on input element itself element.onmouseover = eltMouseOver; element.onmouseout = eltMouseOut; } // set mouseover on input element itself } // loop through elements in form } // iterate through all forms For an example see this page. This works for every input element on the page except the <textarea>. If I move the mouse over the text area you can see the mouse blink after 2 seconds, but the help balloon does not appear unless you first give the <textarea> the focus by clicking the mouse in the area. I have verified by adding alerts that the mouseover and popup functions are called the same way on the <textarea> as on the other input elements. This is on Firefox 3.6.23 on Ubuntu 10.04. Is this just a quirk of Firefox? Hello All, Just a general question about the normal workflow in a professional development environment... This may not have a concrete answer, but just curious if there is an established protocol... Does a front end programmer usually receive strings escaped or does he/she have to process the strings themselves before sending them to functions? Thanks for any thoughts... Happy Holidays. 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! In Brno, 07.06.2011 Hello everybody, i really need your help with one issue. I have got one page running under Wordpress and i would like to add some countdown to widget to show when i will be again online. for example: I am online every working day (monday - friday) from 08:00 AM to 04:30 PM. So it would be nice to show to my subscribers when i would be online again. So lets think about that is Thuesday 07:00 PM, so on my page would be visible this: "I will be back in 13 hours, 00 minutes, 00 seconds" Or in Saturday at 07:00 PM there will be written: "I will be back in 37 hours, 00 minutes, 00 seconds" I would really apreciate every help, thank you in advance! Stefan alias "Scharfheimlich" Hello, I need to improve an existing JavaScript redirect by adding a second redirect based on information contained in the URL. First I will outline the situation, then the specifics: I designed a Realtor website using Joomla 1.5 a few years ago. I will call this SITE-1. The site, SITE-1, displays real estate listing from another site (SITE-2) using iFrames. So the listings from SITE-2 appear to be integrated into the pages of SITE-1. Someone shopping for real estate signs up to be notified of new listings. A new listing comes out and an email is sent to the user with a link to the listing - only the link to the listing is located on SITE-2. So I have been using a JavaScript redirect on SITE-2 that asks the question - "is this in an iFrame" ... if no - redirect to SITE-1 and iframe the results. SITE-1 is ready to receive and parses the new URL: Code: <script language="JavaScript"> <!-- // Start if (window == top) { tops = top.location.href location.replace('http://www.SITE-1.com/index.php?option=com_content&view=article&id=42&Itemid=137&iframe='+tops); } // End --> </script> Now, I have a new problem. I don't have access to SITE-2, I only get to submit a template to them. One of the possible links sent to users from SITE-2 contains a variable in the URL: &id=, followed by a 3 digit number. So the full URL might look like this: http://www.site-2.com/index.php?pg=delacct&id=570 I cannot redirect this to the normal page on SITE-1 because Joomla already uses id=, and it just gets confused and drops a 404 page. Instead I need the code I posted above, to FIRST check for id=. If it exists - go to PAGE-A. If not - then do what the script already does as posted above (we'll call that PAGE-B). Can anyone help? (hopefully I explained that so it can be understood) Thanks, --Kevin I am trying to make a page that shows a daily special for a *fake* pizza place. I want it to detect the day it is, and write the special within the document as an H1 heading or something like that. For testing I have it setup to do an Alert, but it alerts me of the monday special today which is correct, but if I change my system time to another day it doesn't work. Does it work like that or is there a better way to test it? Here is the code, there is a <body onload="getToday()"> in place Code: function getToday() { var d = new Date(); var weekday=new Array(7); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; if (weekday[d.getDay()] = 0) { alert("Buy one Pizza get a second for only $5"); } else if (weekday[d.getDay()] = 1) { alert("Order of Breadsticks for $1"); } else if (weekday[d.getDay()] = 2) { alert("Order of Cinnamon Sticks for $1"); } else if (weekday[d.getDay()] = 3) { alert("Free Two Liter with Pizza Order"); } else if (weekday[d.getDay()] = 4) { alert("Order of Hot Wings for $1"); } else if (weekday[d.getDay()] = 5) { alert("Orders of Breadsticks, Cinnamon Sticks, and 2 liter for $3 with"); } else if (weekday[d.getDay()] = 6) { alert("Breadsticks and a two liter for $1"); } } </script> Hello, this is only for specialist in javascript. I searching a very special javascript, which can be done expire a web site after some identified time(i.e 10days, 20days....). I have made a web site. now i'm looking for, the site expire(or not working at hosting) within 10 days. can I find any special javascript like this? HELLO FELLAS, can someone please show me where get drop down menu like the one goldman sachs uses. take a look please: http://www2.goldmansachs.com/ help is much appreciated julio Hey. Yes, I'm just starting at the beginning and what I'm trying to understand today is adding special characters such as line break, quotes, etc. into Javascript. I'm missing something, however. Can someone please assist? What I'm trying to do is add a line break without having it show /n on the screen. My Code: <html> <head> <title>Exercise 6-20</title> </head> <body><pre> ********* *** * *\n * * * * *** * *\n * * * * ***** * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n * * * * * * *\n ********* *** * * *\n </pre> </body> </html> Thank you, H Hallo. I am a total newbie to JavaScript coding, but I would like to have a price calculator on our internal website. It should calculate the square meter of the product and then multiply it with the square meter price, multiply it with quantity and then plus it with the startup cost. But... if the square meter extend 20 m2 the square meter price should be lower, and also lower when it hit 50 m2. And at 100 m2 it should write that you have to contact sales department. Can this be done with JavaScript? Here is an example: 6 pieces of 2 x 4 meter. 2x4 = 8 m2 6x8 = 48 total m2 48 m2 x price2 x startup = total price I really hope that someone can help me... //Daniel First of all thanks for all the help you are providing. I am looking to alert a user if they type in an character that I am going to not allow for their input box Code: function IsExc (str){ var AllChr = "~ # $ % ^ { } [ ] ' ,"; var AC= AllChr.split(" "); var SC = 0; for (SC=0; SC <= AC.length; SC++){ var ACS = AC[SC]; if (str.search(ACS) >0 ) alert ('Cannot use the characters' + AllChr ) } } For reasons I don't understand the code will not work This code is a bit full on, but it works in IE. I am not suspecting the document.write part, but can anyone tell me why this code fails in Firefox? I think it might be the focus parts in red. Is it not right for FF? Code: function Flash1(tickerstring){ var speedText='<html><head><title>Flashcards - Speed 1</title><script>var sTickString="'+tickerstring+'"</script><script src="flasher(AC).js" language="JavaScript1.2"></script><script>var timeOutVal=300;</script></head> <body onLoad="self.focus()" onBlur="self.focus()"> <a href="javascript:parent.window.focus();top.window.close()"><p align="right"><font face="Arial" color="#808080" size="1"> <i>Close Window</i> </font><p></a><hr><div id=\"bottom_section\"> <\/div>'; function NewWindow(mypage,myname,w,h){ LeftPosition=(screen.width)?(screen.width-w)/2:100; TopPosition=(screen.height)?(screen.height-h)/2:100; settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,resizable=no,status=yes'; win=window.open(mypage,myname,settings); win.document.write(speedText); win.document.close(); if(win.focus){win.focus();} win.refresh; } NewWindow('popup.html','flashcards','620','140'); } I am trying to get a series of dynamic digits from page one to page two via the url. below are the codes have been able to come up with. The problem am having however is that the variables from the first page contains two other characters mainly (=) and (on). therefore, the result i get is like this; 2=on43=on6=on76=on98=on34=on etc What i want displayed are simply the numbers without these two characters. Code: <script> if(window.location.search){ var query = window.location.search.substr(1); var data = query.split("&"); for (var i = 1; i <= 9; i++){ var data = datas[i].split("="); if (unescape(data[1]) == key_str); data.replace(/\=/g," "); } } </script> below is the code that writes the output Code: <script> for (i = 1; (i <= 9); i++) { document.write(data[i]); data[i]="" } </script> thanks Is there an inbuilt function in javascript to convert web characters like
Code: & back to '&' for use in a search text field? Hi guys (and ladies) I am a bit stuck and hope this community might shine a light, or even better can supply me with a solution. I want to do the following: - Having an ordinary webpage containing links - I will link the links with files (word processing files , MS Word, Open Office writer, wordpad or similar) - Now when clicked on the link I want the 'system' to copy the contents of the linked file to the windows clipboard, so when clicking paste, the text from the file is pasted wherever I want. To make clear, I don't want any word processing app to open, just click the link and paste where it needs to be. Possible?? MOST LIKELY but I have no clue how. Any chance someone might know the answer??? I am looking forward to the replies! Thanks PvL |