• 0

[Javascript] Concatenate a variable with nonvariable in HREF element


Question

OK so I want to have a page that links to information on 2-8 different pages so I created an array:

menuURL=new Array;
 menuURL[0]="https://www.neowin.net/"; 	
 menuURL[1]="http://www.google.com";
 menuURL[2]="http://espn.go.com";            

function Page(which){
  location.href=menuURL[which];
}

How would I express in HTML a link to

https://www.neowin.net/news/tags/software/

using the variable menuURL[0]?

Thanks for any help you can give me :)

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Create a select menu with the various pages as options. Then monitor changes to the select element. When there is a change collect the active option and redirect the page to the link corresponding to the option selected using location.href. Hope that helps.

Link to comment
Share on other sites

  • 0

I am not exactly sure what you are asking but here is a link that uses a variable, as you said in your post, as well as concatenation, as you've said in your title.

<a href="#" onclick="window.location = menuURL[0] + 'news/tags/software';">My Link</a>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.