Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2004, 02:42 PM   PM User | #1
Missy_K
New to the CF scene

 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Missy_K is an unknown quantity at this point
Unhappy replace()

Hi, I am really struggling with a solution for a replacment in a string:

I am tring to replace the IMG tag within a sting containing a whole bunch of html code.

All my functions calls work fine. What I am left with is a different IMG tag depending on weather the image is clickable or not.

function getImageBio(htmlIMG)
{
var startHREF = "";
var endHREF = "";
var tempIMG = "";
var bioView = "";

startHREF = htmlIMG.indexOf("<a href=\"bios");
endHREF = htmlIMG.indexOf("Biography'><\a>");
tempIMG = htmlIMG.substring(startHREF.endHREF);

var bioFile = getBio(htmlIMG);
var picFile = getPic(htmlIMG);

if(bioFile == "bios/.")
bioView = viewNoBio(picFile);
else
bioView = viewBio(picFile, bioFile);

htmlIMG.replace(tempIMG, bioView);

return(bioView);
}

The htmlING.replace is where I am getting lost. I need a way to replace the tempIMG string with in the htmlIMG string with the bioView string.

Hope this isn't too confusing. I just can't figure it out. Can anyone help???
Missy_K is offline   Reply With Quote
Old 01-16-2004, 03:29 PM   PM User | #2
Danne
Regular Coder

 
Join Date: Aug 2002
Location: São Paulo, Brazil
Posts: 367
Thanks: 0
Thanked 0 Times in 0 Posts
Danne is an unknown quantity at this point
The replace method works like indexOf and substring - it returns the result:
Code:
htmlIMG=htmlIMG.replace(tempIMG, bioView);
Edit: And the tempIMG should be a RegExp -object.
__________________
/Daniel

Last edited by Danne; 01-16-2004 at 03:55 PM..
Danne is offline   Reply With Quote
Old 01-16-2004, 03:52 PM   PM User | #3
Garadon
Regular Coder

 
Join Date: Jul 2002
Posts: 698
Thanks: 0
Thanked 0 Times in 0 Posts
Garadon is an unknown quantity at this point
u migth wanna put this:

var temp="Biography'><\a>";
endHREF = htmlIMG.indexOf(temp)+temp.length;

instead of the line:

endHREF = htmlIMG.indexOf("Biography'><\a>");

it sort of depends if u want the substring to include the text
Biography'><\a>" or not.
Garadon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:08 AM.


Advertisement
Log in to turn off these ads.