JavaScript - Location Lookup: Google Fusion Table Displaying Map With Multiple Pins
Hey,
I have a location lookup tool that pulls data from a Google Fusion table. User's type their address in and it drops a pin and info window at the place / result that matches their location. It works great with one location, but now I need it to display multiple results / drop multiple pins if they match the criteria Here's the working code that drops one pin (sorry it's a lot): Code: google.load('visualization', '1', {'packages':['corechart', 'table', 'geomap']}); var FusionTableID = 'tableid'; var map = null; var geocoder = null; var infowindow = null; var marker = null; function initialize() { geocoder = new google.maps.Geocoder(); infowindow = new google.maps.InfoWindow({size: new google.maps.Size(150,50) }); // create the map var myOptions = { zoom: 7, center: new google.maps.LatLng(41.9908, -93.4208), mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, navigationControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); layer = new google.maps.FusionTablesLayer({ query: {from:FusionTableID}, styles: [{ polygonOptions: { fillColor:'#000000', fillOpacity: 0.01, strokeColor:'#000000', strokeOpacity: 0.01 } }], suppressInfoWindows:true }); layer.setMap(map); google.maps.event.addListener(layer, "click", function(e) { var content = "<b>"+e.row['name'].value+"</b>"; infowindow.setContent(content); infowindow.setPosition(locationgeocode); infowindow.open(map); }); document.getElementById('submit').onclick = function() { document.getElementById("submit").value = "Searching"; }; } function showAddress(address) { var contentString = address+"<br>Outside Area"; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = results[0].geometry.location; contentString += "<br>"; // query FT for data var queryText ="SELECT 'County', 'Name', 'Location Name', 'Location Address', 'Location City', 'Location State', 'Location Zip', 'geocode' FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.01));"; // document.getElementById('FTQuery').innerHTML = queryText; queryText = encodeURIComponent(queryText); var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText); //set the callback function query.send(openInfoWindowOnMarker); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function openInfoWindowOnMarker(response) { if (!response) { alert('no response'); return; } if (response.isError()) { alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); return; } FTresponse = response; //for more information on the response object, see the documentation //http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse numRows = response.getDataTable().getNumberOfRows(); numCols = response.getDataTable().getNumberOfColumns(); var content = "<b>Outside of Iowa</b><!--"; var unionBounds = null; // alert(numRows); for (var i=0; i < numRows; i++) { var county = FTresponse.getDataTable().getValue(i,0); var precinct = FTresponse.getDataTable().getValue(i,1); var locationname = FTresponse.getDataTable().getValue(i,2); var locationaddress = FTresponse.getDataTable().getValue(i,3); var locationcity = FTresponse.getDataTable().getValue(i,4); var locationstate = FTresponse.getDataTable().getValue(i,5); var locationzip = FTresponse.getDataTable().getValue(i,6); var locationgeocode = FTresponse.getDataTable().getValue(i,7); // var kml = FTresponse.getDataTable().getValue(i,1); // create a geoXml3 parser for the click handlers content = "<b>"+locationname+"</b><br />"+locationaddress+"<br />"+locationcity+locationstate+" "+locationzip+"<br/><a href='http://maps.google.com/maps?daddr="+locationaddress+" "+locationcity+" IA "+locationzip+"' target='_blank' >Click here for Directions</a><br /></br></p><!--"; /* var geoXml = new geoXML3.parser({ map: map, zoom: false }); // alert(kml); geoXml.parseKmlString("<Placemark>"+kml+"<\/Placemark>"); geoXml.docs[0].gpolygons[0].setMap(null); if (!unionBounds) unionBounds = geoXml.docs[0].gpolygons[0].bounds; else unionBounds.union(geoXml.docs[0].gpolygons[0].bounds); */ } // zoom to the bounds // map.fitBounds(unionBounds); setTimeout(function() { google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); infowindow.setContent(content+marker.getPosition().toUrlValue(6)); google.maps.event.trigger(marker, 'click'); document.getElementById("submit").value = "Search"; }, 150); geocoder.geocode( { 'address': locationaddress+","+locationcity+locationstate+" "+locationzip}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var point = results[0].geometry.location; map.setCenter(point); map.setZoom(12); if (marker && marker.setMap) marker.setMap(null); marker = new google.maps.Marker({ map: map, position: point }); }; }); } I basically need it to drop multiple pins if multiple queries match var queryText ="SELECT 'County', 'Name', 'Location Name', 'Location Address', 'Location City', 'Location State', 'Location Zip', 'Hours', 'geocode' FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.01));"; Any thoughts, fixes, or even a point in the right direction would be incredibly helpful. I'm really stuck on this one and have been trying at it for a couple of days now. Even something like getting it to print a second query that I can mark in the table as a second location would be helpful. Something like a second pin that matches: Code: var queryText2 ="SELECT 'County', 'Name', 'Location Name', 'Location Address', 'Location City', 'Location State', 'Location Zip', 'Hours', 'geocode' FROM "+FusionTableID+" WHERE ST_INTERSECTS(\'geometry\', CIRCLE(LATLNG(" + point.toUrlValue(6) + "),0.01)); AND locationname = 'Location 2'"; Thanks!! Similar TutorialsCan anyone give me some advice on how to manipulate Google Fusion Table using Javascript??? I've read the Fusion table's Developer Guider. But still feel confused. Can anyone tell me the specific solution?? Or give me a sample code?? Thanks very much!!!!!! Hi, I am trying to add markers to Google Maps, they are working fine but some of the markers are of same location, thus Google Map will show only one marker for them. Is it possible to show all markers no matter if they are of same location. Help is much appreciated. Thanks I'm trying to make a map that will show your current location, but also load an xml file to show certain attractions in your area. I have the code to work for getting your current location, but I can't figure out how to implement loading the xml file and placing markers based off of that xml file. Here is the code for getting my location: Code: function show_position(p) { document.getElementById('current').innerHTML="latitude="+p.coords.latitude.toFixed(2)+" longitude="+p.coords.longitude.toFixed(2); var pos=new google.maps.LatLng(p.coords.latitude,p.coords.longitude); map.setCenter(pos); map.setZoom(14); var infowindow = new google.maps.InfoWindow({ content: "<strong>yes</strong>" }); var marker = new google.maps.Marker({ position: pos, map: map, title:"You are here" }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); } </script > Can anybody help me figure this out? Thank you in advance Hi: I'm new to this forum and JS. I simply want to be able to use the Google Maps API v3 to allow a location value entered in my app (by the user) to show that location via Google maps. The code below accomplishes this via an onClick event. How to accomplish the same WITHOUT an onClick? To be clear, it appears I need to be able to perform the geocode lookup to get the long/lat coordinates and then apply them. That all needs to occur on page load. Any tips on how to re-arrange this code to accomplish the desire goal are appreciated. Thanks much. Bill Code: <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var geocoder; var map; function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } function codeAddress() { var address = document.getElementById("address").value; geocoder.geocode( { address: address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK && results.length) { // You should always check that a result was returned, as it is // possible to return an empty results object. if (status != google.maps.GeocoderStatus.ZERO_RESULTS) { map.set_center(results[0].geometry.location); var marker = new google.maps.Marker({ position: results[0].geometry.location, map: map }); } } else { alert("Geocode was unsuccessful due to: " + status); } }); } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width: 100%; height: 100%;"></div> <div> <input id="address" type="hidden" value="Chicago"> <input type="button" value="Geocode It!" onClick="codeAddress()"> </div> </body> Hi guys, Hopefully a really quick question. I'm a JS novice, and am looking for a way to output the coordinates of a Google maps marker into the value of two text fields, one for latitude and one for longitude. The code below is a simple location search which returns a result with a draggable marker. Currently, the coordinates in both text fields update when the location search is performed, but not when the marker is dragged to a new location afterwards. Does anyone know the code to simply update the coordinates each time the marker is dropped on a new location? Code: <html> <head> <style type="text/css"> #map_canvas { width:444px; height:444px; overflow:hidden; } </style> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAA-Kl-tQOj5PlnOlXQmp2N9hTg6Fn61x9hOlvMvn6kV4ENK8yRfBShRuj-nulocuk2Alx9JmFKKV4zwA" type="text/javascript"></script> <script type="text/javascript"> var map; var geocoder; function initialize() { map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(52.8068752, -1.6430344),6); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.enableScrollWheelZoom(); geocoder = new GClientGeocoder(); // Update current position info } // addAddressToMap() is called when the geocoder returns an // answer. It adds a marker to the map with an open info window // showing the nicely formatted version of the address and the country code. function addAddressToMap(response) { map.clearOverlays(); if (!response || response.Status.code != 200) { alert("Whoops, we couldn't find that address!"); } else { place = response.Placemark[0]; point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]); marker = new GMarker(point,{draggable:true}); map.addOverlay(marker); marker.openInfoWindowHtml(place.address + '<br /><span class="smallgrey">Zoom in and drag the marker to exactly where the point is</span>'); document.getElementById("latitude").value = point.lat(); document.getElementById("longitude").value = point.lng(); } } // showLocation() is called when you click on the Search button // in the form. It geocodes the address entered into the form // and adds a marker to the map at that location. function showLocation() { var address = document.forms[0].q.value; geocoder.getLocations(address, addAddressToMap); } // findLocation() is used to enter the sample addresses into the form. function findLocation(address) { document.forms[0].q.value = address; showLocation(); } </script> </head> <body onload="initialize()"> <form action="#" onsubmit="showLocation(); return false;"><input type="text" name="q" size="35" /> <input type="submit" name="find" value="Search"/></form> <div id="map_canvas">And pin the <strike>tail</strike> marker on the <strike>donkey</strike> map:<br /></div> Latitude: <input class="required" type="text" name="latitude" id="latitude" value="53.34870686020199" /> <br /> Longitude: <input class="required" type="text" name="longitude" id="longitude" value="-6.267356872558594" /> </body> </html> Many thanks in advance, I appreciate anyone who wants to help out! I am currently working on a project that requires me to get data from a mySQL database in order to create multiple (bar) graphs. I will then display these graphs in the corresponding location using Google Maps. I am having trouble trying to find out how to implement this. Do you guys have any suggestions. Thanks.
Is it possible to use JavaScript to locate all of the "smiley sad Icon.jpg"'s and output the location within the table? Such as A3, and B2. Thank you in advance. Code: <html> <body> <table width="200" border="1"> <tr Id="A"> <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"> </td> <td Id="2"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td> <td Id="3"><img src="http://www.iconeasy.com/icon/thumbnails/System/Icons%20for%20Developers/smiley%20sad%20Icon.jpg"></td> </tr> <tr Id="B"> <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td> <td Id="2"><img src="http://www.iconeasy.com/icon/thumbnails/System/Icons%20for%20Developers/smiley%20sad%20Icon.jpg"></td> <td Id="3"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td> </tr> <tr Id="C"> <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td> <td Id="2"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td> <td Id="3"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td> </tr> </table> </body> </html> I'm trying to make something a lot like a store locator where a user types in their address of origin and submits, then the script compares the driving distances between their entered address and the 4 destination locations that I will store in an array once the page loads. It's kind of hard to describe. I have a form working to do the distance and driving directions once I know which destination will be chosen. This is what I have so far: http://rowsdower.freehostia.com/map_test.php That seems to be working just fine. The problem is that I just can't get anything working that will compare the distance between the origin and each of the options before choosing and displaying directions to the nearest destination. My ultimate goal is to update the list of <options> with PHP and maybe MySQL - though I really don't need this to be large-scale. Then, after the user inputs a starting address if they choose a specific location from the dropdown it will give those directions, otherwise (if the "choose closest location" option is still active) then I will run a comparison of driving distances for each option's address value and store them to an array. Once all locations are read and tested for driving distance I want to take the closest location set that option as selected, and then run the call for driving directions as usual. I know how to pull the option values, how to set and unset the "selected" attribute, and how to check to see if distances need to be compared. I can figure out how to do just about everything I need EXCEPT for getting the google maps API to play along. I've tried so many dead-end ideas that I have just reset my map code to square one. Any ideas for a script piece to run that will return only the driving distance for a list of locations? The onclick event listener would be something like this Code: Array.prototype.findIndex = function(value){ var ctr = ""; for (var i=0; i < this.length; i++) { // use === to check for Matches. ie., identical (===), ; if (this[i] == value) { return i; } } return ctr; }; // ===== request the directions ===== function getDirections() { document.getElementById("directions").style.display="block"; //displays the directions container var saddr = document.getElementById("search1").value; //the user's origin var daddr = document.getElementById("search2").value; //the selected destination if (daddr=="Closest Location") { var distances = [0]; for (i=1;i<document.getElementById("search2").options.length;i++) { //setting i=1 so I skip the "closest Location" option... if (document.getElementById("search2").options[i].selected) { document.getElementById("search2").options[i].removeAttribute("selected"); // de-select each option as we go just in case... } var destination = document.getElementById("search2").options[i].value; // pulling up the stored address //run driving directions comparison here then set "daddr" to the address whose driving distance is least distances[i]=getDrivingDistance(saddr,destination); /* <----- I just made this up, I don't really know how to get this done but I want it to be as simple as this somehow...*/ } daddr = distances.findIndex(distances.min()); // Finds index of the lowest driving distance document.getElementById("search2").options[daddr].setAttribute("selected","selected"); // marks closest location as selected daddr = document.getElementById("search2").options[daddr]; // sets destination address to same index as least distance index } // at this point I have either the user-defined destination or else the closest destination, so I find the directions... var locale = getLocale(); var dirOpts = { locale: locale, getPolyline: true }; if (document.getElementById("walkingDirections").checked) {dirOpts.travelMode = G_TRAVEL_MODE_WALKING;} if (document.getElementById("avoidHighways").checked) {dirOpts.avoidHighways = true;} if (mapPreserveViewport) { dirOpts.preserveViewport = true } gdir.load("from: "+saddr+" to: "+daddr, dirOpts); } I'm going cross-eyed trying to get this working. Does anyone have any ideas for a code blurb to tie this all together? I think everything else should work once I get through the distance iterations but I'm useless with the google maps API... Hi coding world! I am having some serious issues with getting multiple sets of coordinates to appear on google maps on my website. I have many items stored in a database, and each row has a field for latitude and a field for longitude. I get the data like this: PHP Code: $getdeals = "SELECT * FROM deals WHERE cityid='$cityid'"; $result = mysql_query($getdeals); while($row = mysql_fetch_array($result)){ $title = $row['title']; $lat = $row['lat']; $lng = $row['lng']; //THIS IS WHERE I THINK I WOULD TRY TO ADD THE POINT TO THE MAP } If anybody could steer me in the right direction that would be amazing!! Thanks! Hi guys. I have posted about this before on here but I'm still having a lot of issues. MY GOAL - I have a database with a bunch of items and each has latitude, longitude and a category (all the items are within 1 city). I want to have a page that will show a google map, display a marker based on the lat/lng and the image of the marker should be customized based on the category of the row. For example, some rows have a 'food' category and some have a 'health' category - I have specific images I want displayed for each image. I need a script that will plot a marker for each item in my db. I have never used Google maps API before and I'm thinking V3 is what I need to use. Can someone help fill in the code below? PHP Code: $query=mysql_query("SELECT * FROM table"); while($row=mysql_fetch_array($query)){ $lat=$row['lat']; $lng=$row['lng']; $category=$row['category']; //SET MARKER PICTURE TO $category //ADD MARKER TO MAP } Can anybody help out with the code? I don't know javascript that well and I have tried about 40 different things and get nothing but a blank page! THANK YOU SO MUCH Hello, I am trying to create multiple google maps with multiple directions that load on one page. I have tried duplicating the var and function names but I haven't been able to get it to work. Does anyone have any ideas? Any help or suggestions would be greatly appreciated! -Topianno Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example: Advanced Directions</title> <script src=" http://maps.google.com/?file=api&v=2.x&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" type="text/javascript"></script> <style type="text/css"> body { font-family: Verdana, Arial, sans serif; font-size: 11px; margin: 2px; } table.directions th { background-color:#EEEEEE; } img { color: #000000; } </style> <script type="text/javascript"> var map; var map2; var gdir; var gdir2; var geocoder = null; var geocoder2 = null; var addressMarker; var addressMarker2; function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_canvas")); gdir = new GDirections(map, document.getElementById("directions")); GEvent.addListener(gdir, "load", onGDirectionsLoad); GEvent.addListener(gdir, "error", handleErrors); setDirections("San Francisco", "Mountain View", "en_US"); setDirections2("San Francisco", "Mountain View", "en_US"); } } function setDirections(fromAddress, toAddress, locale) { gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale }); } function handleErrors(){ if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code); else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code); else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code); // else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong // alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code); else if (gdir.getStatus().code == G_GEO_BAD_KEY) alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code); else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code); else alert("An unknown error occurred."); } function onGDirectionsLoad(){ // Use this function to access information about the latest load() // results. // e.g. // document.getElementById("getStatus").innerHTML = gdir.getStatus().code; // and yada yada yada... } </script> </head> <body onload="initialize()" onunload="GUnload()"> <h2>Maps API Directions Illustrated</h2> <form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false"> <table> <tr><th align="right">From: </th> <td><input type="text" size="25" id="fromAddress" name="from" value="San Francisco"/></td> <th align="right"> To: </th> <td align="right"><input type="text" size="25" id="toAddress" name="to" value="Mountain View" /></td></tr> <tr><th>Language: </th> <td colspan="3"><select id="locale" name="locale"> <option value="en" selected>English</option> <option value="fr">French</option> <option value="de">German</option> <option value="ja">Japanese</option> <option value="es">Spanish</option> </select> <input name="submit" type="submit" value="Get Directions!" /> </td></tr> </table> </form> <br/> <table class="directions"> <tr><th>Formatted Directions</th><th>Map</th></tr> <tr> <td valign="top"><div id="directions" style="width: 275px"></div></td> <td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td> </tr> </table> <h2>Maps API Directions Illustrated 2nd Map</h2> <form action="#" onsubmit="setDirections2(this.from.value, this.to.value, this.locale.value); return false"> <table> <tr><th align="right">From: </th> <td><input type="text" size="25" id="fromAddress2" name="from" value="San Francisco"/></td> <th align="right"> To: </th> <td align="right"><input type="text" size="25" id="toAddress2" name="to" value="Mountain View" /></td></tr> <tr><th>Language: </th> <td colspan="3"><select id="locale" name="locale2"> <option value="en" selected>English</option> <option value="fr">French</option> <option value="de">German</option> <option value="ja">Japanese</option> <option value="es">Spanish</option> </select> <input name="submit" type="submit" value="Get Directions!" /> </td></tr> </table> </form> <br/> <table class="directions"> <tr><th>Formatted Directions</th><th>Map</th></tr> <tr> <td valign="top"><div id="directions" style="width: 275px"></div></td> <td valign="top"><div id="map_canvas" style="width: 310px; height: 400px"></div></td> </tr> </table> </body> </html> I would like to use the gallery whose code is provided on this page: http://www.meadmiracle.com/SlidingGallery.aspx I tried to display two galleries with the same settings and so I put: $(function() { $('div.gallery img').slidingGallery({ container: $('div.gallery') }); $('div.gallery2 img').slidingGallery({ container: $('div.gallery2') }); }); with the divs being "gallery2" but the coding only works when I put the code without "gallery2". Am I coding it wrong? Code: <script language="JavaScript" type="text/javascript"> function confirmDelete(url){ var decision = confirm("Click OK to delete this post."); if(decision == true){ window.location = url; } } </script> <!--HTML LATER ON --> <a onclick="confirmDelete('deletePost.php?id=17')" href=''><img src='delete.png' alt='' title='Delete this post' /></a> I get absolutely nothing out of this. The confirm box pops up, but a the URL never changes when I click OK. I have no clue what's going wrong here. I'm using Google Chrome to test this out if that helps. Also does not work in Firefox. Hello all! Quick question regarding basic cookies. I have a button that runs a function that creates a cookie onclick; document.cookie = ("cookie1=500"); whenever i display this later, despite the fact i've clicked the button 3 times. It only displays once. Is there a way I could display this AS MANY TIMES as the button was clicked. Any help is appreciated. Code: <script type="text/javascript"> var cookies = document.cookie; var cookie_name = new Array(); var cookie_value = new Array(); if (cookies.length > 0 ) { var cookies = cookies.split("; "); for( var x = 0 ; x < cookies.length ; x++ ) { var cookie_parts = cookies[x].split("="); cookie_name[x] = cookie_parts[0]; cookie_value[x] = cookie_parts[1]; } } function writeProducts() { function removeItem() { cookie_name[x] + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; } var total = 0; var tempstring = ""; var prodTable = document.getElementById('tblProducts'); var prodRow; var prodQuantity; var prodName; var prodPrice; for( var x = 0 ; x < (cookie_name.length) ; x = x + 1) { prodRow = document.createElement('tr'); prodName = document.createElement('td'); prodPrice = document.createElement('td'); prodCheck = document.createElement('td'); prodName.innerHTML = cookie_name[x]; prodPrice.innerHTML = "$" + cookie_value[x]; prodCheck.innerHTML = tempstring + '<input type="button" value="Remove from Cart" />' total = parseInt(total + parseInt(cookie_value[x])); prodRow.appendChild(prodName); prodRow.appendChild(prodPrice); prodRow.appendChild(prodCheck); prodTable.appendChild(prodRow); } document.getElementById('spnProducts').innerHTML = tempstring; tempstring = tempstring + "Total :" + " " + '$' + total; document.getElementById('spnTotal').innerHTML = tempstring; } <script> I am having trouble implementing this script. I am not a coder so please give exact, idiot proof advise. :-) Thank You. <script> (function() { var cx = 'user_id:field_id1'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); // This basically takes the value of the radio button (requires jQuery) $("input:radio[name='GCSField']").change(function() { cx = $(this).val(); }); })(); </script> <label for="user1"> <input name=GCSField id="user1" type="radio" value="user_id:field_id1" checked >User Field 1 </label> <label for="user2"> <input name=GCSField id="user2" type="radio" value="user_id:field_id2">User Field 2 </label> <gcse:search></gcse:search> Here is my html. <!DOCTYPE html> <html> <head><meta charset="UTF-8"> <!--[if lt IE 9]><script src=http://html5shiv.googlecode.com/svn/trunk/html5.js></script><![endif]--> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <title>TEST</title> <meta name="robots" content="noindex, nofollow"> <meta name="viewport" content=" width=device-width, initial-scale=1"><meta name="HandheldFriendly" content="true"><meta name="MobileOptimized" content="320"> <style>body{width:100%;max-width:25em;margin-left:auto;margin-right:auto;font-family:Verdana,'Palatino Linotype',Palatino,'Book Antiqua',Arial,Helvetica,sans-serif;text-align:justify;font-size:105%;background-color:#000;background:#000;}p{margin-bottom:1%;}strong{font-size:115%;font-weight:bold;}a{line-height:200%;text-decoration:underline;color:#0007C6;}article{margin: 0 0 1% 0; color:#000;background:#FEE800;background-color:#FEE800; text-align: center;}</style> </head><body> <article> <div><script> (function() { var cx = 'user_id:field_id1'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.google.com/cse/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); // This basically takes the value of the radio button (requires jQuery) $("input:radio[name='GCSField']").change(function() { cx = $(this).val(); }); })(); </script> <label for="user1"> <input name=GCSField id="user1" type="radio" value="011565775292567206849:xkh-s7ljiug" checked >User Field 1 </label> <label for="user2"> <input name=GCSField id="user2" type="radio" value="partner-pub-4173665486685435:n2tml3-z5vf">User Field 2 </label> <gcse:search></gcse:search></div> <div><gcse:searchresults></gcse:searchresults></div> </article> </body></html> Here is the above page off a server TEST Thanks again. I am trying to create a form field which has a button attached to it which when clicked will open a popup search window used to search for a record which can search by a record id or record data and then when a record is selected it will close the popup window and enter the caption into a locked text field and store the record id in a hidden field. When the form is submitted it should pass the record id to the form handler.
I am looking for a simple script or I hope it seems. I need the script to function like this: [text box] insert telephone number here in format like this xxx-xxx-xxxx but once the number is entered I would like for it to auto detect the area code and in a box or just as text to the right or left I would like for it to display the state that the area code corresponds with. I am using a set of predetermined area codes that I can enter myself once I am made aware of the script. IF this is possible then I would greatly appreciate the help! Hi, I'm using the following Javascript code to show a div layer depending on the URL Code: <script type="text/javascript"> if (location.href.match(/folder/)) { document.getElementById("div-layer").style.display="block"; } </script> This works perfectly when I visit http://www.domain.com/folder but I do not want it to match any subfolders beneath /folder, for example: http://www.domain.com/folder/sub-folder http://www.domain.com/folder/sub-folder2 etc. Does anyone know how I can modify the code to only match /folder or /folder/ and no subfolders beneath it? Thank you in advance. Where can I get a script that looks up IP addresses and domain name just like http://cqcounter.com/whois/ I've seached everywhere without sucess. Thanks in advance. Hey, i am just trying to learn javascript and my friend gave me a little assignment to try and figure out. i am having trouble figuring it out and need some help. basically i just want to display the information in my associative array, into an html table. var NFC_east = new Array(); NFC_east[0]=["Giants", 16, 0, "Eli Manning"]; NFC_east[1]=["Cowboys", 0, 16, "Tony Romo"]; NFC_east[2]=["Redskins", 0, 16, "Donnovan McNabb"]; NFC_east[3]=["Eagles", 0, 16, "Mike Vick"]; that's my array. now i need to display that in a table with a Team column, wins column, loses column, and a quarterback column. i basically want to do this using a for loop, and he gave me a hint about using a nested while loop as well somehow. i know i need to use getElementById, id, and innerHTML stuff but i just don't know how to do it. i cant find anything to help me with this simple task, hoping someone here could help. |