简体   繁体   中英

Passing a variable to javascript via a link

My website has a javascript variable (addselectedsubdivision) that loads a neighborhood name from a box on the left to a box on the right. I was hoping I could build a link and then us PHP to add the subdivision letter, neighborhood, and city so that when you click on the link it goes right to this page and loads the neighborhood name in the box on the right. However, I can't get the variable to pass to the new page. Any suggestions?

Website: http://www.mlsfinder.com/va_rein/jonmcachran/index.cfm?primarySearchType=sold&searchType=subdivision&so=a&domain=www.jonsellsvb.com&subdivision_string=p

Example link:

<a href="http://www.mlsfinder.com/va_rein/jonmcachran/index.cfm?primarySearchType=sold&searchType=subdivision&so=a&domain=www.jonsellsvb.com&subdivision_string=$firstletter" onLoad="addselectedsubdivision($neighborhood||$city);" target="_blank">

What is the onLoad attribute meant to do?

In index.cfm you will need to have coldfusion code that will output a javascript statement based on the query parameters.
So when the serverside sees that it has the arguuments $neighborhood and $city then it will output

...
addselectedsubdivision("cityfromquerystring");
...

This code will have to be contained in an window.onload = function() {...} or equivalent block in order to only be executed after the page has loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM