www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  Scripting    Concatenate array value break url
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Posted
My script below works fine in WebPublisher to create multiple links based on two fields - the Video link field (linkv) and the Title of the video (titlev). However it does not always work when I concatenate the fields to create a clickable link. If have urls have spaces (like in the array example below) the hyperlink stops at the space even though I can get script to successfully write the full video link outside of a concatenated html string for a hyperlink. Any thoughts?


<SCRIPT language="JavaScript"><!--

var linkv = new Array ("http://intranet/program 1.htm","http://intranet/program 2.htm","http://intranet/program 3.htm","http://intranet/program 4.htm","http://intranet/program 5.htm","http://intranet/program 6.htm");

var titlev= new Array ("Program 1","Program 2","Program 3","Program 4","Program 5","Program 6");


nentry = linkv.length;
nentry1 = titlev.length;

for (i = 0; i < nentry; i++) {
f1 = linkv[i].toString(); // Convert entry to string
f2 = titlev[i].toString(); // Convert entry to string
str = "<a href=" + f1 + ">" + f2 + "</a><br>"; // Concatenate
document.write(str);
}

//--></SCRIPT>

This message has been edited. Last edited by: JennM,
 
Posts: 153 | Registered: Tue June 08 2004Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Okay figured it out... and have replaced spaces with %20

for (i = 0; i < nentry; i++) {
f1 = linkv[i].toString(); // Convert entry to string
f1 = f1.replace(/\s/g,"%20")
f2 = titlev[i].toString(); // Convert entry to string
str = "<a href=" +f1 + ">" + f2 + "</a><br>"; // Concatenate
document.write(str);
 
Posts: 153 | Registered: Tue June 08 2004Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
JennM ---

You're probably best off url-encoding the URL strings in your array right off the bat, rather than selectively replacing spaces with %20. Thus you will ensure that *all* characters are URL safe, not just spaces.

E.g.
  
var linkv = [encodeURI("your link string"), encodeURI("another link string"), etc.];


js encode method comparisons


Peter Tyrrell, MLIS
Senior Consultant
Andornot Consulting Inc.
http://www.andornot.com/about/developerblog
 
Posts: 179 | Location: Vancouver, BC, Canada | Registered: Thu September 20 2001Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Thanks Peter. I will try that.
 
Posts: 153 | Registered: Tue June 08 2004Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

www.Inmagic.com    Inmagic Forums    Inmagic Forums  Hop To Forum Categories  Scripting    Concatenate array value break url