JavaScript - Getting Text Between Specified Characters
I'm trying to figure out the proper way to correctly get each full-formation of encoded html (of Unicode), so that I could assign each HTML encoding with its each Unicode characters
HTML Encoded Unicode: &#2344;&#2351;&#2366; &#2344;&#2375;&#2346;&#2366;&#2354; I want to retrieve each encoded HTML and assign them into array like this Code: var my_array = new Array(); my_array [0] = "2344"; my_array [1] = "2351"; my_array [2] = "2366"; my_array [3] = "2344"; my_array [4] = "2375"; my_array [5] = "2346"; my_array [6] = "2366"; my_array [7] = "2354"; Thanks in Advance for helps Similar TutorialsI am using the below javascript to verify a text input box but I would also like to require atleast 3 characters being entered before allowing the user to search. How do I accomplish that? Thanks in advance! Code: <script language="JavaScript"> <!-- /*********************************************** * Required field(s) validation v1.10- By NavSurf * Visit Nav Surf at http://navsurf.com * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/ function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("words"); // Enter field description to appear in the dialog box var fieldDescription = Array("Company Name"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> Hello I have this snippet for controlling the number of characters entered in a textarea. It works. But, if I replace in this code the name "my_form" by "contact-form" and "my_text" by "message", it doesnt ! It looks like the keyword is " my_form ". You change that , and the script will not work! It turns out that I have to change those names because the form as it was already had those names my_form and message before I added this counter And I dont want to replace the names of the form in order to adapt them to this code snippet below. The question is why would the script not work if I have just replaced two words, which dont seem to be keywords of JS programming (my_form and my_text) <html><head> <title>(Type a title for your page here)</title> <script language=JavaScript> <!-- function check_length(my_form) { maxLen = 50; // max number of characters allowed if (my_form.my_text.value.length >= maxLen) { // Alert message if maximum limit is reached. // If required Alert can be removed. var msg = "You have reached your maximum limit of characters allowed"; alert(msg); // Reached the Maximum length so trim the textarea my_form.my_text.value = my_form.my_text.value.substring(0, maxLen); } else{ // Maximum length not reached so update the value of my_text counter my_form.text_num.value = maxLen - my_form.my_text.value.length;} } //--> </script> </head> <body> <form name=my_form method=post> <textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_text rows=4 cols=30></textarea> <br> <input size=1 value=50 name=text_num> Characters Left </form> </body> </html> Need to know how to define hex characters for the following; var x = hex value var y new Array(hex value, hex value, etc) document.write(hex value) Can some one help me, I want to replace the characters from a string and I have tried with this script: Code: var v5=form.description.value.replace(/#/, "%23"); But it only changes the first character from the string. Turning #### into %23### but I want them all transformed. 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 Hi I have a CMS system using Tinymce and after making some alterations noticed the updates weren't showing up. After much messing (sql, set up etc) I started to delete the content bits at a time and came to the conclusion that is was the character ' as in what's any ideas why this is and how to solve it i'm thinking its due to php code! Cheers I have a textbox ( I am using asp.net ). I want to use that textarea as rich text box. The text in textarea is submitted to database and then displayed. So, I can use <b><u> tags, but I want to use smileys too. I need a simple code for it. My logic is simple..., Whatever text is written inside the textarea is first read and when a group of specific character like Code: " :) ;) x-(" are found, that characters should be colored to red . So, a Code: :) will appear as Code: :) . This logic is simple but I am new to javascript programming, it cant implement it. Can a provide a javascript for this, or if you have better but simple code plz let me know. How can to obtain length of string variable, for example if I have: var msg = 'hello world!'; Does it exist a method to count string characters? My credit card processing service will only accept English characters. I need to detect entries in the form that are using non English characters. Is there a way in Javascript to create a function to force a string to UTF-8? My idea is to do something like function forceUTF8(X){ Y = ???? X; return Y; } if ( stringA != forceUTF8(stringA) alert ("You must use English Characters"); Code: <script type="text/javascript" src="external.php?type=js"></script> <script language="" type="text/javascript"> <!-- for (x = 0; x < 10; x++) { document.writeln("<a href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a>, "); } //--> </script> My code will display 10 posts, however at the very end it will display an extra ", " which bugs me. How can I strip those last two characters. hi all, am doing a check on my fields, so that they only contain certain characters and numbers. i have this. var validEntry = /^[a-zA-Z0-9@$&"]+/; but this also captures a space in between words as an error. can somebody please tell me on how to avoid this. thanks. Hi, So I've got an array called questions_raw Code: questions raw = [ ["<Q1> Question", "choice1","choice2", "choice3"], ["<Q2> Question", "choice1","choice2", "choice3"], ... ] And I want to list all of the questions, but not the choices/answers. So far, I've managed to list just the questions, but because another function randomly sorts them, I need to sort them back into numerical order for a separate function (displaying the questions) I use characters (>,^) at the front to separate them into different answer types (just to explain the code) I try this to cut each string down so that they can be sorted numerically/alphebetically - Code: function linearlist() { var list = []; var tempStr = ""; for (var l = 0; l < 145; l++) { tempStr = questions_raw[l][0]; list[l] = tempStr; } if (list.charAt(0)== " " ) list = list.substring(3) ; if (list.charAt(0)== ">" ) list = list.substring(3) ; if (list.charAt(0)== "^" ) list = list.substring(3) ; var sorted = list.sort(); document.Qtext2form.Qtext2.value = sorted.join("\n"); } But it doesn't like it - because "it has no method charAt" Any idea what i'm missing? Is it just that you have to put the [l] in every time you call a variable? Cheers I have a simple function like this: Code: function chars_remaining() { var remaining = 200 - document.getElementById("text_box").value.length; document.getElementById("number").innerHTML = 'Characters Remaining: ' + remaining; } And I call this onkeyup on the textarea. 200 chars max and what happens is when they type a character, it will still stay at 200 until they press another key. So when it will be 199, it should actually be 198. Onkeyup, onkeydown, onkeypress will all do the same thing. How can I make it so that as soon as they press a key it changes right away? Also I insert this into my database with mysql_real_escape_string, which is limited at 200 chars. When they keep typing and get to 0 remaining characters if they had any quotes, backslashes, etc. they will get added and thus some of their text will be cut off. I.e. lets say the text ended with "good luck". If they had 3 quotes in their text it might end up being "good l" instead because 3 backslashes had to be used to escape. So would the best thing to do be to count a quote, backslash, etc. as two characters instead of one. How would I do that in JS? So, I have this javasript code in HEAD <script type="text/javascript"> <!-- function validateThis(registerForm) { if (registerForm.firstname.value == 'Name') { alert("Oops"); return false; } else { return true; } } //--> </script> with this form in BODY <form action="register.php" method="post" name="registerForm" onSubmit="return validateThis(this)"> <input type="text" value="Name" onclick="if(this.value=='Name'){this.value=''}" onblur="if(this.value==''){this.value='Name'}" name="firstname"> </form> and I want to put a text with Greek characters instead of value "Name". I tried it and the "function validateThis" didn't work. The form just passes it and returns true. I tried also hexadecimal code,HTML entities and numeric HTML entities and didn't work either. What I should I do? Thank you in advance! As of right now I have a code that will work in IE but wont work in FireFox...go figure. Basically what I want to have happen is when you type in an area code it will provide an output in a predetermined area of the page. For Example: Input- 512 Output - Austin, TX The code that I have doesn't work with firefox and I was just wondering if there was a code that would allow that to happen. Thanks! 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 Hi guys, This has been asked before, and i've seen many of the previous posts. And tried for hours. But finally i've broken and have to ask for help. What am I doing wrong here? Can someone please explain? Code: var u=document.forms["lead"]["name"].value; var v=document.forms["lead"]["city"].value; var x=document.forms["lead"]["country"].value; var y=document.forms["lead"]["mobile"].value; var z=document.forms["lead"]["email"].value; if (u==null || u=="") { alert("Please enter your first name."); return false; } if (v==null || v=="") { alert("Please enter your city."); return false; } if (isNaN(lead.y.value)) { alert("bloody work!"); return false; } if (x=="Argentina" && y.length < 11) { alert("Please enter a valid Argentinian phone number."); return false; } Thanks in advance. Hi chaps, Ive got a project and ive been steaming ahead with it myself for a bit, i was given the code to start off with but have adapted it for my own needs. As well as fieldOne being a minimum of 3 characters I also need to check if the first three characters are the same because we get a lot of spam. Thanks in advance Code: function showResults(results) { var fieldOne = document.getElementById('edtName').value; var minLength = 3; if (!results.Status.Success) { //alert(results.Status.ErrorMessage); window.location = "There has been an error. Please try again." } else if ( results.Result && fieldOne.length > minLength ) { document.forms[0].action = 'getmoreinfo.php'; } else if ( results.Result && fieldOne.length < minLength ) { document.forms[0].action = 'getlost.php'; } else { document.forms[0].action = 'getafreeguide.php'; } document.forms[0].submit(); } Hi everyone. I do all of my writing and editing in notepad but can't figure out how to use characters from different charsets in the same script-block. For example if I wanted to write Code: if ( CharInput=="ش" ) { N = 1;} if ( CharInput=="厜" ) { N = 2;} I've found the unicode the number for ش is 0634 and 厜 is 539C. But I don't know how to use them. My question is how do I modify the above piece of code so it works in something like notepad? I can't cut and paste them in because in plain text files like that of notepad the formating is lost and I'm pretty sure html wouldn't allow that anyway. Thanks for reading |