in the code below I an trying to replace a string with another string, then write the new string in JavaScript tags. But the result is not what I wanted: first the original string was not replaced, second plain text is shown, instead of popping up an alert. Is there a way I can replace the string and execute the command?
When trying to emulate php's nl2br() function in javascript, I ran into something quite disturbing.
Code: cms.t.value = cms.t.value.replace(/ /gi, '<br /> '); Using this piece of code, I was really surprised that the newlines weren't preceded by <br />, but by <br>. I really don't understand why that would happen. Why can't I decide my own replacement string? .
<script type="text/javascript"> var str="Welcome to Microsoft! Microsoft Microsoft"; var stringToBeFound = 'Microsoft' var ReplaceString = 'site' document.write(str.replace(stringToBeFound , ReplaceString )); </script>
My problem is im trying to use string.replace that is not case sensitive and replace every string found. I could use regular expression with it but my stringToBeFound is a dynamic variable im getting it from my database
I have a function defined in my document's <head> section which adds a <script> tag to a specified <div> tag. The added <script> has a src="" attribute pointing to a PHP file, which dynamically returns JavaScript. In Safari, the src file isn't downloaded. Neither is any code contained within the new script tag [such as alert()]. In IE(6) and Firefox, this works as expected. Here's my code:
I need help with substring or trim function in javascript. Find below my code. Selection holds the value Select State, and length of the string is 14. I need to equate the Selection value to string "Select State" and execute alert message.
function selected_item() { if (Selection=="Select State") alert("Select the State");[code]....
I tried this:
var state=Selection.substring(0,11); and then string would be equated to state variable. But it is not working.
I ran into a problem that I could not fix myself, I am trying to replace a string with another string, the replace lines look like this:
Code: var word = document.getElementById("word").innerHTML; document.getElementById("word").innerHTML = wordd.replace(/B/g, '<span class="style106">B</span><span class="style107"> </span>'); It works just perfectly if left alone, but I need to replace every letter inside this string, adding those style and span tags around each and every letter. So if I add another line to this code, like this:
PHP has a function called nl2br() which takes all the newlines in a string and turns them into break tags <br>. I need to do the same in javascript. Is this about right? I'm not sure how one is supposed to reference invisible characters in Javascript strings. I took an example on the web and tried to modify it to my uses.
function nl2br_js(myString) { var regX = / /gi ;
s = new String(myString); s = s.replace(regX, "<br /> "); return s; }
After looking around quite a bit using Google, I still couldn't find out what the gi in the above example is for. What is it?
I have the following Javascript code to write a code to the page using InnerHTML. But instead of writing the code, it shows the content of the iframe. How can I make the code write straight text of the HTML code...
I am trying to replace new line character with the <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 need to replace custom tags to spans. I have: Code: <block style="color:blue" class="block01" limit="100">This is a block</block> I need to fetch the attributes and add them to a span, like: Code: <span style="color:blue" class="block01" limit="100">This is a block</span> There's a few on the page so I need to change all of them some may have many attributes.
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).
On my site I use an SVG image. The <embed> tag works fine in Opera and Firefox. And <img> works fine in Chrome and Safari. I would like to know if it is possible to change the tag with an 'if' browser statement, and if it is ho would I write it.
if (jQuery.browser.webkit) { * // Replace <embed> with <img> }
i am trying to make an online graphing calculator with javascript. dont ask how because i dont know. but there is an annoying error in a do...while loop. although it should break out of the loop when the |'s (absolute value signs) are replaced with Math.abs( and ). here is the code.
I have my website getting a value as a result of an ajax call. After that, I would like to insert that result (a string) into a tag. However, I would like to insert that result in a way that (1) it must have opacity = 0, then (2) it will slideDown() so the whole content list being pushed down using animation, and finally (3) change opacity = 1. Imagine this is just like a Facebook message list insert process The way I am planning to do this is to return the result string from ajax to opacity=0 first. However, I don't know how to use jQuery to select a tag from within a string. I know jQuery only select from the DOM. So how to do this?
I was tring to write a function to make that took the letters that a user is searching for and making the first occurrence of it bold in the results (ignoring the case).
>From reading javascript books and looking at posts in this group, I
thought this would work. Perhaps I misunderstood what $1 is. But in the results, I am getting a bold $1 with IE6.
How can I determine what the occurrence of the phrase is in the correct case?
I realize I can write this parsing the string without regular expressions but I thought this would be cleaner.
var match = new RegExp( escapeCharsForRegExp(typedLetters), "i"); if (match.test(text)) { text = text.replace(match, '<b>' + '$1' + '</b>' ); }
I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I supposed to write this function?
String.replace(/</g,'<');
2)
While I'm on the subject, anyone know why they implemented replace using a slash delimiter instead of quotes? I know it's how it's done in Perl but why is it done that way?
3)
One last regexp question: is it possible to do something like this: String.replace(/<(.*?)>(.*?)</$1>/ig,'<$1>$2</$1>'); This is just an example where a sub-match used in a regular expression must sub-match again exactly as it did the first time later in the same string. But I don't know how to do that in a regexp although it seems like it should be possible.
I would like to select the text of this td and replace with another string. How can that be accomplished?
<td jscontent="address" style="vertical-align: middle; width: 100%;" jstcache="9">8050 Drexel Ct, Lemon Grove, CA 91945</td> I tried with this without any success: var vtd = $(".googledir tr td:contains('8050 Drexel Ct, Lemon Grove, CA 91945')").html('8050 Blossom Lane, Lemon Grove, CA 91945');
Now I need to do some string replace in chatmsg.value, ie, I need to look for some piece of text in chatmsg.value, and in case they are present (there may be multiple occurences of the same), to replace them with something else. This is what I got by doing a google search: Code:
function replaceAll( str, from, to ) { var idx = str.indexOf( from );
while ( idx > -1 ) { str = str.replace( from, to ); idx = str.indexOf( from ); } return str;}
chatmsg.value = replaceAll( chatmsg.value, "string to replace", "new string" ); And I place this second function just above the previous one. But it's not working. Any help friends?