zeidhaddadin Posted December 3, 2006 Share Posted December 3, 2006 Hi all, How can I do the following:I have an array, each element of this array contains a string which is a site URL such as:myarray[0] = "http://www.google.com"so how can I print it (the whole string) and make it a link to the url it contains, I have got this but it is not working: document.write("<a href=\"urlsarray[x]\">" + urlsarray[x] + "</a>" + "<br />") Thanks in advance,zeid Link to comment Share on other sites More sharing options...
Skynet Posted December 3, 2006 Share Posted December 3, 2006 I am new to JavaScript but I am assuming that you are using something to the effect of: for (x in urlsarray) {document.write("<a href=\"urlsarray[x]\">" + urlsarray[x] + "</a>" + "<br />")// other code} The problem lies in the first part of your statement I believe. Each time the for iterates, it writes this to the HTML document <a href="urlsarray[x]">http://www.google.com</a><br /> You need to separat the "<a href=\"urlsarray[x]\">" into <a href=\"" + urlsarray[x] + "\"" "document.write("<a href=\"" + urlsarray[x] + "\">" + urlsarray[x] + "</a>" + "<br />") This should make your code work (I think).Try it and see what happens. Link to comment Share on other sites More sharing options...
Webworldx Posted December 3, 2006 Share Posted December 3, 2006 document.write("<a href='" + urlsarray[x] + "'>" + urlsarray[x] + "</a><br />"); Link to comment Share on other sites More sharing options...
zeidhaddadin Posted December 3, 2006 Author Share Posted December 3, 2006 Thanks very much guys! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now