469,347 Members | 21,063 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,347 developers. It's quick & easy.

Using a variable in JS replace method

This seems like such an easy one, but I can't seem to figure it out or find any answers. I think I might be doing something wrong besides the obvious.

I'm trying to replace a particular variable with a string (specifically, a line break). I'm trying this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (flashsrc.indexOf('americancultist.com') == -1) {
  3.      document.getElementById('flashinput').replace(embedTag, '\n');
  4. }
  5.  
Is there an obvious reason this isn't working for me? It's kind of a mess right now, but I'm uploading the whole page anyway if you care to peruse it:

http://www.americancultist.com/videosource2.html

What I'm attempting to do here is strip out embed tags that don't come from a certain domain upon form submission. But I don't need a solution to the larger problem for now -- just wondering why this particular step isn't working.
Aug 15 '07 #1
4 1482
mrhoo
428 256MB
You are trying to use a String method on an object.
Aug 15 '07 #2
Oh, that was my mistake -- just an alternative I was trying. I originally had this:

Expand|Select|Wrap|Line Numbers
  1.         if (flashsrc.indexOf('americancultist.com') == -1) {
  2.             field1val.replace(embedTag, '\n');
  3.         }
  4.  
But that didn't work, either. When I insert an alert afterwards for the value of field1val, it comes up with the variable embedTag unreplaced.
Aug 15 '07 #3
Figured it out:

Expand|Select|Wrap|Line Numbers
  1.         if (flashsrc.indexOf('americancultist.com') == -1) {
  2.             field1val = field1val.replace(embedTag, '\n');
  3.             document.getElementById('flashinput').value = field1val;
  4.         }
  5.  
I thought using the replace method would change the string itself, but it doesn't. The string has to be set equal to it.
Aug 15 '07 #4
I thought using the replace method would change the string itself, but it doesn't. The string has to be set equal to it.
JavaScript strings are immutable : ) (they can never be changed once constructed)
Aug 15 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by stephane | last post: by
3 posts views Thread by Yan | last post: by
2 posts views Thread by X l e c t r i c | last post: by
15 posts views Thread by r0g | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.