473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1607
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

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

Similar topics

6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
5
by: Mark | last post by:
Hi All, Is there a way to (whilst using the sendobject command) use a query as the source of email addresses. I ask this because the list is constanly changing and I don't want to keep going into...
1
by: stephane | last post by:
I have a problem which must be in this : print" <script type='text/javascript'> document.location.replace('http://127.0.0.1/add_task.php?req_id={$maxValue}&tk_request_name={$req_name}');...
11
by: ctman770 | last post by:
Hi Everyone, Is it faster to save the precise location of an html dom node into a variable in js, or to use getElementById everytime you need to access the node? I want to make my application...
4
by: moondaddy | last post by:
I need to edit the text in many files so I'm writing a small routine to do this. First I have a method that loops through all the files in a directory and passes the full file path to another...
1
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
3
by: Yan | last post by:
Hi, I don't seem to be able to use for_each if it should replace a 'for' loop in a method (constructor in my case) and inside that 'for' loop a class member variable is being accessed. The...
2
by: X l e c t r i c | last post by:
Here: http://bigbangfodder.fileave.com/res/sandr.html I'm trying to use string.replace() for a basic search and replace form using textarea values as the regexp and replacement values for...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
1
by: faultykid | last post by:
I would like to store a variable then call it back later. I have a variable on line 198 www = ''+this._ad.clickUrl+''; and on line 321 i try document.write(www);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.