javascript - How do I concatenate several different variables to create a URL -


i'm trying use loop generate bunch of different urls use in table via javascript.

the final url want is: http://www.enviroptics.com/ecommerce/environmentally-sealed-thermocouple-nb4-caxl-14u-12-aag.html

the url broken down 4 sections:

  1. prefix: 'http://www.enviroptics.com/ecommerce/'
  2. product name: 'environmentally-sealed-thermocouple-'
  3. product number: 'nb4-caxl-14u-12-aag'
  4. suffix: '.html'

the prefix , suffix wont changing. product name stay same within javascript want separate variable because plan on making bunch of javascripts, 1 each different product name. product number change each different row , link in table.

this have far:

var eo_url_1 = 'http://www.enviroptics.com/ecommerce/'; var eo_url_ext = "environmentally-sealed-thermocouple-" var eo_url_2 = '.html'; 

i have loop generating part number , when use console log this:

console.log(eopartnum[i]); //yields following part number results //nb4-caxl-14u-12-aag //nb4-caxl-14u-12-bag //nb4-caxl-14u-12-cag //(24 more similar results) 

so example eopartnum[0] = nb4-caxl-14u-12-aag. tried use concatenate everything:

window.navtoprod = function() {   window.document.location = eo_url_1.concat(eo_url_ext,eopartnum[i],eo_url_2); } 

but seems giving me error part number either trying direct me 'http://www.enviroptics.com/ecommerce/environmentally-sealed-thermocouple-undefined' or 'http://www.enviroptics.com/ecommerce/environmentally-sealed-thermocouple-[object%20text]'

here w3 i've been working in: http://www.w3schools.com/code/tryit.asp?filename=f0vl5u0mks2h

all other answers here valid if wanting interpolate variable values string. looking @ w3 example provided, instead think issue more variable scope, in have generic method , looping on products, lose concept of variable eopartnums is.

for specific example, may better instead read product code direct table row, see changed method below

window.navtoprod = function(evt) {   var eo_url_1 = 'http://www.enviroptics.com/ecommerce/';   var eo_url_2 = '.html';   var partnum = evt.target.parentnode.children[0].innertext;   window.document.location = eo_url_1.concat(eo_url_ext,partnum,eo_url_2); } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -