javascript - Pass dynamic string value to function -


i have array of names , on 100 geographic coordinates. dynamically creating appended html table of 5 closest coordinates specified address. want conditional statement based on selected address in list of 5 closest addresses. able pass numeric values supporting function string value isn't being passed function, required conditional logic. if plug in value parameter showrouteb() function work, when try plug in city.name or variable assigned city.name function doesn't seem called. couldn't find errors when checked console in chrome , i've tried several different variations. see obvious syntax or logic errors?

my code is:

            (i = 0; < 5; i++) {             city = top101citiesus[i];                                                    //dynamically load map_table                             tbody += '<tr>';             tbody += '<td>';             tbody += '<a href=#'+city.name+' onclick=showrouteb('+city.name+')>' +city.name+ '</a>';              //tbody +=  city.name +  city.lat + ',' + city.lng;             tbody += '</a>';             tbody += '</td>'             tbody += '</tr>';             } 

.....i append string values table header + table body + table footer

    function showrouteb(x){       var element = document.getelementbyid('prouteb');        element.innerhtml = "this city name " + x;                       } 

you need add quotes around strings, otherwise treated variables.

tbody += '<a href=#'+city.name+' onclick=showrouteb("'+city.name+'")>' +city.name+ '</a>'; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -