Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript direcotry listing impossible to figure out!

Status
Not open for further replies.

dingoegret

Programmer
Dec 22, 2011
3
Okay first things first. Firebug this website [URL unfurl="true"]http://www.locksmith.com/[/url]

You will see that they have a script in the head tag. That script is:
<script class="yext-synd-74qWXpBkYak=">
(function () {
var el = document.createElement('script');
el.async = true;
el.src = '//s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=&latitude=&longitude=';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(el);
})();
</script>

They also have a form. That form is:
<form title="Enter your zip and find a qualified, local locksmith" action="results.asp" method="POST">
<p><font style="font-size: 19px; font-weight: 700">FIND A LOCKSMITH</font>
<input type="text" value="14646" style="font-family: Arial; font-size: 22px; color: #666666; font-weight:bold;" onclick="this.value=''" size="5" name="zip">
<input type="image" style="position: relative; top:5px" name="B1" src="images/smallgo2.jpg">
</p>
</form>

When you enter your zip code into that form, I think it is passed to the el.src variable as a parsed string and sent to s.yext-listings.com/ like this://s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=INSERT_ZIP_CODE_PASSED_FROM_THE_FORM_HERE&latitude=&longitude=

When you click the submit button on the form with an input zip code, it takes you to a page where there is a huge DIV block with this script executing inside it:
<script class="yext-synd-74qWXpBkYak=">


(function () {
var el = document.createElement('script');
el.async = true;
el.src = '//s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=33405&latitude=&longitude=';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(el);



})();



</script>

Well the result on the second page is a listing pulled from a database and laid out in the second page in a DIV block.


My question! How do I emulate this on my website? I have the Yext service. I have been on the phone with the company for over a week now and I cant get any technical support on the integration. Apparently they are having a lot of lay offs and technical support is unavailable.

I am assuming that I need to build a form in HTML and have it pass the zip code to that JavaScript snippet somehow? I also want to know how the JavaScript on the second page renders a listing result from that passed form value?

Thank you so much for the help in advance. I know you guys can figure this out before I do.
 
I get an OLDBC error from that page:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[MySQL][ODBC 5.1 Driver][mysqld-5.1.34-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND locations.latitude BETWEEN '19.2992002868652' AND '19.5692002868652' AND loc' at line 1

/index.asp, line 69

With that said however, Your assumptions aren't exactly accurate based on the code you posted.

<script class="yext-synd-74qWXpBkYak=">
(function () {
var el = document.createElement('script');
el.async = true;
el.src = '//s.yext-listings.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=&latitude=&longitude=';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(el);
})();
</script>

All this does is execute the function when the page load which basically creates a new <script> section, and plugs in code from the s.yext-listings.com website. It is in no way related to the zipcode form below.

This:
<form title="Enter your zip and find a qualified, local locksmith" action="results.asp" method="POST">
<p><font style="font-size: 19px; font-weight: 700">FIND A LOCKSMITH</font>
<input type="text" value="14646" style="font-family: Arial; font-size: 22px; color: #666666; font-weight:bold;" onclick="this.value=''" size="5" name="zip">
<input type="image" style="position: relative; top:5px" name="B1" src="images/smallgo2.jpg">
</p>
</form>

Simply posts the provided zipcode to the results.asp which apparently again loads in the javascript function as before, but this time with the provided zip code from the form.

In other words the first page doesn't really do anything beyond taking the input in the form and handing it over to the second page.

You'll need to grab the zipcode value in your second page, and plug it into the zip parameter of the yest url.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
I think I found the code that writes the second page. My question is, where in that code does it receive results from yest to use to write to the document?

Code:
<script>
(function(){var goog=goog||{};goog.require=goog.provide=function(){};if(!goog.string)goog.string={};
goog.string.htmlEscape=function(a,b){if(b)return a.replace(goog.string.amperRe_,"&amp;").replace(goog.string.ltRe_,"&lt;").replace(goog.string.gtRe_,"&gt;").replace(goog.string.quotRe_,"&quot;");else{if(!goog.string.allRe_.test(a))return a;if(a.indexOf("&")!=-1)a=a.replace(goog.string.amperRe_,"&amp;");if(a.indexOf("<")!=-1)a=a.replace(goog.string.ltRe_,"&lt;");if(a.indexOf(">")!=-1)a=a.replace(goog.string.gtRe_,"&gt;");if(a.indexOf('"')!=-1)a=a.replace(goog.string.quotRe_,"&quot;");return a}};
goog.string.amperRe_=/&/g;goog.string.ltRe_=/</g;goog.string.gtRe_=/>/g;goog.string.quotRe_=/\"/g;goog.string.allRe_=/[&<>\"]/;var soy={$$escapeHtml:goog.string.htmlEscape};soy.$$changeNewlineToBr=function(a){a=String(a);if(!soy.$$CHANGE_NEWLINE_TO_BR_RE_.test(a))return a;return a.replace(/(\r\n|\r|\n)/g,"<br>")};soy.$$CHANGE_NEWLINE_TO_BR_RE_=/[\r\n]/;var yext={synd:{templates:{}}};
goog.provide("yext.synd.templates");goog.require("soy");
yext.synd.templates.displayListings=function(b){var d="";if(b.data.listings.length>0){d+='<br /><br /><h3 id="yextheader">Featured Listings by Yext</h3>';if(b.data.numPages>1){d+="<center>"+(b.data.currentPage>0?'<a id="'+soy.$$escapeHtml(b.data.className)+'-prev" href="javascript:;">\u00ab</a> ':"\u00ab ");var e=b.data.numPages;for(var c=0;c<e;c++)d+=c!=b.data.currentPage?'<a id="'+soy.$$escapeHtml(b.data.className)+"-"+soy.$$escapeHtml(c)+'" href="javascript:;">'+soy.$$escapeHtml(c+1)+"</a> ":soy.$$escapeHtml(c+
1)+" ";d+=(b.data.currentPage<b.data.numPages-1?'<a id="'+soy.$$escapeHtml(b.data.className)+'-next" href="javascript:;">\u00bb</a>':"\u00bb")+"</center>"}b=b.data.listings;e=b.length;for(c=0;c<e;c++){var a=b[c];d+='<div class="loclisting"><div style="float:left; width:50%;"><b style="font-size:14px;"><a href="[URL unfurl="true"]http://www.locksmith.com/details.asp?'+soy.$$escapeHtml(a.profileParams)+'"[/URL] class="locname">'+soy.$$escapeHtml(a.name)+"</a></b><br>"+(a.address?'<div class="locaddress">'+soy.$$escapeHtml(a.address)+
","+(a.address2?soy.$$escapeHtml(a.address2)+",":"")+'</div><div class="loccity">'+soy.$$escapeHtml(a.city)+',</div> <div class="locstate">'+soy.$$escapeHtml(a.state)+'</div> <div class="zip">'+soy.$$escapeHtml(a.zip)+"</div>":'<div class="locaddress">Serving Your Area</div>')+'</div><!-- this /div closes the left-floating div, holding name & address --\><div class="locphone"><a href="[URL unfurl="true"]http://www.locksmith.com/details.asp?'+soy.$$escapeHtml(a.profileParams)+'">'+(a.areaCode?"("+soy.$$escapeHtml(a.areaCode)+[/URL]
") "+soy.$$escapeHtml(a.exchange)+"-"+soy.$$escapeHtml(a.lastFour):soy.$$escapeHtml(a.phone))+'</a></div><!-- /div closes locphone --\></div><!-- this /div closes loclisting --\><div style="height:0; clear:both;"><!-- spacer --\></div><a href="javascript:void(0)" onclick="" class="more" id="more'+soy.$$escapeHtml(c)+'">More Details</a><div id="details'+soy.$$escapeHtml(c)+'" class="details" style="display:none;"><div class="description">'+(a.description?soy.$$escapeHtml(a.description):"")+'</div><div class="services">'+
(a.services?soy.$$escapeHtml(a.services):"")+'</div><div class="hours">'+(a.hours?soy.$$escapeHtml(a.hours):"")+'</div></div><a href="javascript:void(0)" onclick="" class="less" id="less'+soy.$$escapeHtml(c)+'" style="display:none;">Less Details</a><div style="height:0; clear:both;"><!--spacer--\></div>'}}return d};var adUnitId="74qWXpBkYak=";var templateFn=yext.synd.templates.displayListings;var soyContext={"data":{"currentPage":0,"numPages":1,"listings":[{"zip":"33401","services":"Locksmiths, 24 Hour Locksmiths, Auto Locksmiths, Commercial Locksmiths, Emergency Locksmiths, Residential Locksmiths, Lock Installation, Lock Repair, Master Key Services, Re-key Services, Biometric Locks, Combination Locks, Digital Locks, Magnetic Locks, Alarm Systems, CCTV Systems, Intercom Systems","phone":"5613707659","adLevel":"GOLD","areaCode":"561","hours":"M-Su 24hr","link":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/pls-locksmith-miami2.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","state":"FL","city":"West[/URL] Palm Beach","product":"CALLS","description":"Welcome to P.L.S locksmith # 1 in customer satisfaction. \r\n\r\nWe are a mobile service, we do not have a physical location!\r\n\r\nWe do not make motorcycle keys!\r\n\r\nWe offer 24/7 local mobile locksmith service, fast response time to all of your residential, commercial and automotive locksmith service needs. \r\nIf you're in need of locksmith service or emergency locksmith service all across the country, you can count on us to be there for you and provide fast professional and affordable locksmith service. \r\nIf you're locked out of your car, home or business and are in need of emergency service, please call us, We offer a wide range of locksmith services all across the country.\r\nP.L.S Locksmith is a family owned and operated business that believes customer service is very important for future refrences and company growth. \r\nCall us today and experience the P.L.S way. \r\nIf you are a realtor, bank or property manager and need Locksmith service, contact us to disscus special corprate pricing. We will beat any reasonable estimate! \r\nSome of our locksmith services include: \r\n\u2022Basic, medium, and high security locks \r\n\u2022Residential lockout \r\n\u2022Commercial lockout \r\n\u2022Master key system \r\n\u2022Car lockout \r\n\u2022Car keys/chip keys, cut and programmed \r\n\u2022Residential locks \r\n\u2022Commercial locks \r\n\u2022Safes","name":"P.L.S. Locksmith","profileParams":"loc=pls-locksmith-miami2&pid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","longitude":-80.05806,"latitude":26.719854,"profileURL":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/pls-locksmith-miami2.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","lastFour":"7659","exchange":"370"},{"zip":"33480","services":"Locksmiths,[/URL] 24 Hour Locksmiths, Auto Locksmiths, Commercial Locksmiths, Emergency Locksmiths, Residential Locksmiths, Lock Installation, Lock Repair, Master Key Services, Re-key Services, Biometric Locks, Combination Locks, Digital Locks, Magnetic Locks, Alarm Systems, CCTV Systems, Intercom Systems, Key Copies, Key Cuts","phone":"9543434977","adLevel":"GOLD","areaCode":"954","hours":"M-Su 24hr","link":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/locksmith-point-palm-beach-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","state":"FL","city":"Palm[/URL] Beach","product":"CALLS","name":"Locksmith Point","profileParams":"loc=locksmith-point-palm-beach-florida&pid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","longitude":-80.038948,"latitude":26.7174,"profileURL":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/locksmith-point-palm-beach-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","lastFour":"4977","exchange":"343"},{"zip":"33076","services":"Locksmiths,[/URL] 24 Hour Locksmiths, Auto Locksmiths, Commercial Locksmiths, Emergency Locksmiths, Residential Locksmiths, Lock Installation, Lock Repair, Master Key Services, Re-key Services, Biometric Locks, Combination Locks, Digital Locks, Magnetic Locks, Alarm Systems, CCTV Systems","phone":"9548710997","adLevel":"GOLD","areaCode":"954","hours":"M-Su 24hr","link":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/1-respond-locksmith-pompano-beach-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","state":"FL","city":"Pompano[/URL] Beach","product":"CALLS","description":"1 Respond Locksmith Provides 24 hour residential locksmith solutions for private homes and commercial locksmith services for corporations in small communities and metropolitan areas alike. We also provide auto locksmith services for car lockout emergencies. All of our security expert technicians are licensed insured and backed by a national service provider with a strong brand name. We not only guarantee the most professional service you will receive, but the quickest solutions to your security needs as well. We specialize in lock changing, lock installation, and lock re-key, car lockouts, ignition keys, high security locks, intercom systems, CCtv, gate installation, garage doors and more. Not only are we professional locksmiths, but we also pride ourselves on the high quality customer service. 1 Respond Locksmith is experienced in residential, commercial, emergency, and automotive locksmith services.What ever you problem may be we have an option for you and we are only 15 minutes away.","name":"1 Respond Locksmith","profileParams":"loc=1-respond-locksmith-pompano-beach-florida&pid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","longitude":-80.140514,"latitude":26.250007,"profileURL":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/1-respond-locksmith-pompano-beach-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","lastFour":"0997","exchange":"871"},{"zip":"33065","services":"Locksmiths,[/URL] 24 Hour Locksmiths, Auto Locksmiths, Commercial Locksmiths, Emergency Locksmiths, Residential Locksmiths, Lock Installation, Lock Repair, Master Key Services, Re-key Services, Biometric Locks, Combination Locks, Digital Locks, Magnetic Locks, Alarm Systems, CCTV Systems, Intercom Systems","phone":"9547806965","adLevel":"GOLD","areaCode":"954","hours":"M-Su 24hr","link":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/pls-locksmith-coral-springs-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","state":"FL","city":"Coral[/URL] Springs","product":"CALLS","description":"Welcome to P.L.S locksmith # 1 in customer satisfaction. \r\n\r\nWe are a mobile service, we do not have a physical location!\r\n\r\nWe do not make motorcycle keys!\r\n\r\nWe offer 24/7 local mobile locksmith service, fast response time to all of your residential, commercial and automotive locksmith service needs. \r\nIf you're in need of locksmith service or emergency locksmith service all across the country, you can count on us to be there for you and provide fast professional and affordable locksmith service. \r\nIf you're locked out of your car, home or business and are in need of emergency service, please call us, We offer a wide range of locksmith services all across the country.\r\nP.L.S Locksmith is a family owned and operated business that believes customer service is very important for future refrences and company growth. \r\nCall us today and experience the P.L.S way. \r\nIf you are a realtor, bank or property manager and need Locksmith service, contact us to disscus special corprate pricing. We will beat any reasonable estimate! \r\nSome of our locksmith services include: \r\n\u2022Basic, medium, and high security locks \r\n\u2022Residential lockout \r\n\u2022Commercial lockout \r\n\u2022Master key system \r\n\u2022Car lockout \r\n\u2022Car keys/chip keys, cut and programmed \r\n\u2022Residential locks \r\n\u2022Commercial locks \r\n\u2022Safes","name":"PLS Locksmith","profileParams":"loc=pls-locksmith-coral-springs-florida&pid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","longitude":-80.260448,"latitude":26.27102,"profileURL":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/pls-locksmith-coral-springs-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","lastFour":"6965","exchange":"780"},{"zip":"33321","services":"Locksmiths,[/URL] 24 Hour Locksmiths, Auto Locksmiths, Commercial Locksmiths, Emergency Locksmiths, Residential Locksmiths, Lock Installation, Lock Repair, Master Key Services, Re-key Services, Biometric Locks, Combination Locks, Digital Locks, Magnetic Locks, Alarm Systems, CCTV Systems, Intercom Systems","phone":"9548745816","adLevel":"GOLD","areaCode":"954","hours":"M-Su 24hr","link":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/mobile-locksmith-tamarac-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","state":"FL","city":"Tamarac","product":"CALLS","description":"Welcome[/URL] to our locksmith # 1 in customer satisfaction. \r\nWe offer 24/7 local mobile locksmith service, fast response time to all of your residential, commercial and automotive locksmith service needs. \r\nIf you're in need of locksmith service or emergency locksmith service all across Florida, you can count on us to be there for you and provide fast professional and affordable locksmith service. \r\nIf you're locked out of your car, home or business and are in need of emergency service, please call us, We offer a wide range of locksmith services all across Florida.\r\nOur Locksmith is a family owned and operated business that believes customer service is very important for future references and company growth. \r\nCall us today and experience our way. \r\nIf you are a Realtor, bank or property manager and need Locksmith service, contact us to discuss special corporate pricing. We will beat any reasonable estimate! \r\nSome of our locksmith services include: \r\n\u2022Basic, medium, and high security locks \r\n\u2022Residential lockout \r\n\u2022Commercial lockout \r\n\u2022Master key system \r\n\u2022Car lockout \r\n\u2022Car keys/chip keys, cut and programmed \r\n\u2022Residential locks \r\n\u2022Commercial locks \r\n\u2022Safes","name":"24/7 Local Locksmith","profileParams":"loc=mobile-locksmith-tamarac-florida&pid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","longitude":-80.27092,"latitude":26.215053,"profileURL":"[URL unfurl="true"]http://www.yext-listings.com/l/firstplaceinternet/mobile-locksmith-tamarac-florida.html?srid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D","lastFour":"5816","exchange":"874"}[/URL]]}};var listings=soyContext.data.listings;var beaconImageUrl="//s.yext-numbers.com/imp?pid=QdH%2Fe6hIUwugcsOoPel0Lg%3D%3D";
var reqUrl='//s.yext-numbers.com/yext?aid=74qWXpBkYak%3D&city=&state=&zip=33405&latitude=&longitude=';
var yextGlobal;yextGlobal=typeof window.__YEXT__=="undefined"?window.__YEXT__={}:window.__YEXT__;
var className="yext-synd-"+adUnitId,findScriptTagWithoutAd=function(){var a=document.getElementsByTagName("script");for(var b=0;b<a.length;b++){var c=a[b];if(c.className==className)return c}},findAd=function(){var a=document.getElementsByTagName("script");for(var b=0;b<a.length;b++){var c=a[b];if(c.className==className)if((c=c.nextSibling)&&c.className==className)return c}},changePage=function(a,b,c){if(b=findAd(b)){b.context.data.currentPage=c;b.innerHTML=templateFn(b.context);(function(){var d=
document.createElement("script");d.async=true;d.src=a+"&page="+c;(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(d)})()}},attach=function(a,b){a.addEventListener?a.addEventListener("click",b,false):a.attachEvent("onclick",b)},attachPage=function(a,b,c,d){attach(a,function(){changePage(b,c,d)})},scriptEl=findScriptTagWithoutAd(),renderGadget=function(){soyContext.data.className=className;var a=document.createElement("div");a.innerHTML=templateFn(soyContext);
a.context=soyContext;a.className=className;scriptEl.nextSibling&&scriptEl.nextSibling.className==className&&scriptEl.parentNode.removeChild(scriptEl.nextSibling);scriptEl.parentNode.insertBefore(a,scriptEl.nextSibling);(a=document.getElementById(className+"-prev"))&&attachPage(a,reqUrl,className,soyContext.data.currentPage-1);for(a=0;a<soyContext.data.numPages;a++){var b=document.getElementById(className+"-"+a);b&&attachPage(b,reqUrl,className,a)}(a=document.getElementById(className+"-next"))&&attachPage(a,
reqUrl,className,soyContext.data.currentPage+1);if(beaconImageUrl)(new Image).src=beaconImageUrl};scriptEl&&renderGadget();
})();
</script>
 
I figured it out with the help of my developer, thanks! : D
 
care you share the solution so others can learn?

Jason Meckley
Senior Programmer

faq855-7190
faq732-7259
My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top