JavaScript - Need Help Adding Parsing To Google's Rssdisplayer.js
The rssdisplayer.js code works well enough, however, clicking on the generated rss news link updates the current html page with the feed. Not a good idea since I don't want people leaving my website.
So, the script that builds the href link looks like this: var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>" I want to add target="_blank" for obvious reasons. Can anyone tell me how to do this? Similar TutorialsHi, I'm not sure where I have translated this incorrectly. I have one google map embedded on my page which works fine. But I wanted to add a second one. I thought the easiest way to do this would be to have a second page which is called later on with all the details on it for the second map. However although I think (this I presume is where I went wrong) I have replicated the instructions correctly the place holder for the second map just remains blank. This is the code for my called page with the instructions for the second map: PHP Code: <?php echo $_POST['Map'] . '<br />'; ?> <div id="placemap_canvas"></div> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #placemap_canvas {width:100%; height:150px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM regions WHERE RegionPId='{$_POST['Map']}'"); while($row = mysql_fetch_array($result)){ echo $row['maplink']; } mysql_close($con); ?> ); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("placemap_canvas"), myOptions); } </script> And this is the script of the main page, just in case I would be better off keeping them both in one place. Code: <head> <script type="text/javascript"> function loadSubPlace(File,ID,Msg,Eile,EID,Esg){ loadXMLDoc1(File,ID,Msg); var mimer = setTimeout(function(){loadXMLDoc1(Eile,EID,Esg)},5000); } </script> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html {height:250px} body {height:250px} #map_canvas {width:30%; height:250px;} </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true" /> </script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng ( <?php include("dbconnect.php"); $result = mysql_query("SELECT * FROM countries WHERE Country='{$_SESSION['Country']}'"); while($row = mysql_fetch_array($result)){ echo $row['Map']; } mysql_close($con); ?>); var myOptions = { zoom: 4, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> </head> <body onload="initialize()"> <div class="countryright" id="map_canvas"> include("dbconnect.php"); $snowball=explode(';',$_POST['syringa']); $turnsol=$snowball[1]; $violet =$snowball[2]; $wakerobin=$snowball[3]; global $turnsol; global $violet; global $wakerobin; echo '<center><b><big>' . $wakerobin. '</big></b></center><br /><br />'; $result=mysql_query("SELECT * FROM regions WHERE country='{$turnsol}' AND region='{$violet}' AND place='{$wakerobin}' AND sub !='' ORDER BY sub ASC"); while($row = mysql_fetch_array($result)){ $wheat="{$row['RegionPId']};{$turnsol};{$violet};{$wakerobin};{$row['sub']}"; $tigerlilly=$row['RegionPId']; echo '<input type="button" class="button3" name="place" id="place" value="' . $row['sub'] . '" onclick="loadSubPlace(\'getPlace.php\',\'txtHintPlaceSub\',\'hepatica=' . urlencode($wheat) . '\',\'getPlaceMap.php\',\'placemapcanvas\',\'Map=' . urlencode($tigerlilly) . '\');" />'; } echo '<input type="button" class="button3" name="addplace" id="addplace" value="Add Place" onclick="loadXMLDoc1(\'getAddPlaceSub.php\',\'txtHintPlaceSub\', encodeURI(\'addsubplace=' . $_POST['syringa'] . '\'));" />'; echo '<br /><br /><div id="txtHintPlaceSub"></div><br /><br />'; mysql_close($con); ?> I've cut out the script that doesn't relate to this so I hope I haven't missed anything important. Hi, I noticed that RSS Feed entries are linked to their source when using rssdisplayer.js (see "A robust RSS Feed displayer" in Javascriptkit.com). Can anyone show me how to link the the source url provided in the feed to something different, like linkTarget_blank. The option takes a string and will be used to specify the link target of the image. Please PM the modified rssdisplayer.js script. I really need your help guys. Thanks Bastos A noob needs some help. I'm using a combination of Yahoo Pipes and rssdisplayer.js to display some snippets from several RSS feeds on a new site I'm building. The trouble I'm having is that (i) the feeds don't update when I refresh the page, I think because a cached version of the page is being loaded, and (ii) I'd like to have the div containing the feeds auto-refresh at a given time interval. I've got a Twitter javascript working that does both these things, but can't work out how to get the rssdisplayer.js working this way. The rssdisplayer code is: Code: google.load("feeds", "1") //Load Google Ajax Feed API (version 1) function rssdisplayer(divid, url, feedlimit, showoptions){ this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description") var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API feedpointer.setNumEntries(feedlimit) //set number of items to display document.write('<div id="'+divid+'">Loading feed...</div>') this.feedcontainer=document.getElementById(divid) var displayer=this feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed } rssdisplayer.prototype.formatdate=function(datestr){ var itemdate=new Date(datestr) return "<span style='color:gray; font-size: 90%'>"+itemdate.toLocaleString()+"</span>" } rssdisplayer.prototype.formatoutput=function(result){ if (!result.error){ //if RSS feed successfully fetched var thefeeds=result.feed.entries //get all feed entries as a JSON array var rssoutput="<ul>" for (var i=0; i<thefeeds.length; i++){ //loop through entries var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>" var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : "" var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : "" rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li>" } rssoutput+="</ul>" this.feedcontainer.innerHTML=rssoutput } else //else, output error alert("Error fetching feeds: "+result.error.message) } //USAGE SYNTAX: new rssdisplayer("divid", "rssurl", numberofitems, "displayoptions") //new rssdisplayer("adiv", "http://www.cssdrive.com/index.php/news/rss_2.0/", 5, "date, description") I've been looking for a solid solution for how to add numbers to markers. Most that I've seen involve an asp page with a post back of an image based on the query string. I am trying to do something like what MarkerClusterer does. Here is an example: http://google-maps-utility-library-v...e_example.html I've looked over their code and cant seem to pull out the part where it adds the numbers to the marker, I'm still new to jquery. Here is a link to the source code: http://google-maps-utility-library-v...erclusterer.js any help would be appreciated. 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 I am learning to programme in HTML5 and Java, and I'd like some assistance with what I am sure is a pretty basic matter, if possible please? If anyone can assist it would be most appreciated? I am using Dreamweaver (latest version)... This code here below when run produces a google map with a street address look up input. I am wanting to learn how to look up an address and submit this to resolve within the map, and also to insert a place holder... I'd like the look up box to sit within (and overlay) the map top left area - at the moment it sits below the map - which i guess is because I haven't inserted a frame?? Many Thanks grin): ***CODE*** <!DOCTYPE html> <html> <head> <style type="text/css"> html, body, #map-canvas { height: 100%; margin: 5; padding: 5;} </style> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> function initialize() { var mapOptions = { center: { lat: -34.397, lng: 150.644}, zoom: 8 }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); } google.maps.event.addDomListener(window, 'load', initialize); </script> </head> <body> <div id="map-canvas"></div> </body> <head> <title>Place Autocomplete Address Form</title> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> html, body, #map-canvas { height: 100%; margin: 0px; padding: 0px } </style> <link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script> <script> // This example displays an address form, using the autocomplete feature // of the Google Places API to help users fill in the information. var placeSearch, autocomplete; var componentForm = { street_number: 'short_name', route: 'long_name', locality: 'long_name', administrative_area_level_1: 'short_name', country: 'long_name', postal_code: 'short_name' }; function initialize() { // Create the autocomplete object, restricting the search // to geographical location types. autocomplete = new google.maps.places.Autocomplete( /** @type {HTMLInputElement} */(document.getElementById('autocomplete')), { types: ['geocode'] }); // When the user selects an address from the dropdown, // populate the address fields in the form. google.maps.event.addListener(autocomplete, 'place_changed', function() { fillInAddress(); }); } // [START region_fillform] function fillInAddress() { // Get the place details from the autocomplete object. var place = autocomplete.getPlace(); for (var component in componentForm) { document.getElementById(component).value = ''; document.getElementById(component).disabled = false; } // Get each component of the address from the place details // and fill the corresponding field on the form. for (var i = 0; i < place.address_components.length; i++) { var addressType = place.address_components[i].types[0]; if (componentForm[addressType]) { var val = place.address_components[i][componentForm[addressType]]; document.getElementById(addressType).value = val; } } } // [END region_fillform] // [START region_geolocation] // Bias the autocomplete object to the user's geographical location, // as supplied by the browser's 'navigator.geolocation' object. function geolocate() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var geolocation = new google.maps.LatLng( position.coords.latitude, position.coords.longitude); autocomplete.setBounds(new google.maps.LatLngBounds(geolocation, geolocation)); }); } } // [END region_geolocation] </script> <style> #locationField, #controls { position: relative; width: 480px; } #autocomplete { position: absolute; top: 0px; left: 0px; width: 99%; } .label { text-align: right; font-weight: bold; width: 100px; color: #303030; } #address { border: 1px solid #000090; background-color: #f0f0ff; width: 480px; padding-right: 2px; } #address td { font-size: 10pt; } .field { width: 99%; } .slimField { width: 80px; } .wideField { width: 200px; } #locationField { height: 20px; margin-bottom: 2px; } </style> </head> <body onload="initialize()"> <div id="locationField"> <input id="autocomplete" placeholder="Enter your address" onFocus="geolocate()" type="text"></input> </div> <table id="address"> <tr> <td class="label">Street address</td> <td class="slimField"><input class="field" id="street_number" disabled="true"></input></td> <td class="wideField" colspan="2"><input class="field" id="route" disabled="true"></input></td> </tr> <tr> <td class="label">City</td> <td class="wideField" colspan="3"><input class="field" id="locality" disabled="true"></input></td> </tr> <tr> <td class="label">State</td> <td class="slimField"><input class="field" id="administrative_area_level_1" disabled="true"></input></td> <td class="label">Zip code</td> <td class="wideField"><input class="field" id="postal_code" disabled="true"></input></td> </tr> <tr> <td class="label">Country</td> <td class="wideField" colspan="3"><input class="field" id="country" disabled="true"></input></td> </tr> </table> </body> </html> I'm having a little bit of trouble with setting up a Google map to add markers for events venues. The page is dynamically created using postcodes from a database which is why the code might look a little strange, but it's the only way I could find to make it work. However, I'm struggling to add any further functionality to the page. As you will see from the code attached I would like to add buttons to reset the map to it's initial state, plus buttons to show only the "O" markers or the "E" markers. Also, I would ideally only like to see the "O" markers when the page first loads. I know this is a lot to ask but could anyone please help. Thanks Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>HPB Open days and Exhibitions Locator</title> <style type="text/css"> html { } body { margin: 0; padding: 0; height: 100%; background-color:#000; } #map { width: 980px; height: 580px; z-index:1; position:relative; margin:25px auto; } .controls { background-color:#597681; padding:10px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; } .controls p { margin:0; padding:0; color:#FFF; font-size:12px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; } .introtext { position:absolute; top:10px; left:0px; width:425px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; } .introtext h2 { margin:0; padding:10px 20px; background-color:#000; color:#FFF; font-size:24px; font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif; font-style:italic; font-weight:normal; } .introtext p { margin:0; padding:10px 20px; background-color:#BF443A; color:#FFF; font-size:12px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; } .introtext h2 strong { font-weight:bold; } #postcode {width:150px; color:#999;} </style> <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=ABQIAAAAQJTCOfFBzEZfb0xYTu1h_BR0_9owy9VLLEJCKI_ZedHr-0NdXxQd9Q8sR1hC7s4PNGNVmIaTUQvspA" type="text/javascript"></script> <script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAQJTCOfFBzEZfb0xYTu1h_BR0_9owy9VLLEJCKI_ZedHr-0NdXxQd9Q8sR1hC7s4PNGNVmIaTUQvspA" type="text/javascript"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script> <script type="text/javascript"> function doBlur() { if (document.getElementById('postcode').value == '') { document.getElementById('postcode').value = 'Postcode'; document.getElementById('postcode').style.color = '#999'; } }; function doFocus() { if (document.getElementById('postcode').value == 'Postcode') { document.getElementById('postcode').value = ''; document.getElementById('postcode').style.color = '#000'; } }; function doSwitch() { if (document.getElementById('postcode').value == 'Postcode') {alert('Valid postcode required');} else { usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint); } }; </script> </head> <body> <div id="map"> </div> <script type="text/javascript"> var map; var localSearch = new GlocalSearch(); var icon = new GIcon(); icon.image = "markers/yellow_MarkerO.png"; icon.shadow = "http://www.google.com/mapfiles/shadow50.png"; icon.iconSize = new GSize(20, 34); icon.shadowSize = new GSize(37, 34); icon.iconAnchor = new GPoint(10, 34); icon.infoWindowAnchor = new GPoint(10, 0); var icon2 = new GIcon(); icon2.image = "markers/blue_MarkerE.png"; icon2.shadow = "http://www.google.com/mapfiles/shadow50.png"; icon2.iconSize = new GSize(20, 34); icon2.shadowSize = new GSize(37, 34); icon2.iconAnchor = new GPoint(10, 34); icon2.infoWindowAnchor = new GPoint(10, 0); var icon3 = new GIcon(); icon3.image = "http://www.google.com/mapfiles/marker.png"; icon3.shadow = "http://www.google.com/mapfiles/shadow50.png"; icon3.iconSize = new GSize(20, 34); icon3.shadowSize = new GSize(37, 34); icon3.iconAnchor = new GPoint(10, 34); function usePointFromPostcode(postcode, callbackFunction) { localSearch.setSearchCompleteCallback(null, function() { if (localSearch.results[0]) { var resultLat = localSearch.results[0].lat; var resultLng = localSearch.results[0].lng; var anotherpoint = new GLatLng(resultLat,resultLng - 1.20000); var point = new GLatLng(resultLat,resultLng); callbackFunction(point, anotherpoint); } else { alert("Postcode not found!"); } }); localSearch.execute(postcode + ", UK"); } if (GBrowserIsCompatible()) { function createMarker(point,html) { var marker4 = new GMarker(point,icon); GEvent.addListener(marker4, "click", function() { marker4.openInfoWindowHtml(html, { noCloseOnClick: false }); }); return marker4; } function createMarker2(point2,html) { var marker2 = new GMarker(point2,icon2); GEvent.addListener(marker2, "click", function() { marker2.openInfoWindowHtml(html, { noCloseOnClick: false }); }); return marker2; } var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(53.80000, -8.41387), 6); map.addControl(new GLargeMapControl3D(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10))); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } function placeMarkerAtPoint(point, anotherpoint) { var marker3 = new GMarker(point,icon3); map.addOverlay(marker3); map.setCenter(anotherpoint, 8); } </script> <script type="text/javascript"> $(document).ready(function(){ $("#map").append("<div class='introtext'><div class='controls'></div></div>"); $("#map > .introtext").prepend("<h2>Forthcoming <strong>shows</strong></h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce mauris eros, sollicitudin in rhoncus in, pharetra a lorem. Nunc semper lectus ut libero interdum ut pharetra ipsum mattis.</p>"); $("#map > .introtext > .controls").append("<p>Find a show</p><input type='text' id='postcode' size='10' value='Postcode' onFocus='doFocus();' onBlur='doBlur();' /><input type='submit' value='Search' onClick='doSwitch();' id='yourlocation' /><input type='submit' value='reset' id='iliketoreset' /><input type='submit' value='set E' id='ionlywantex' /> <input type='submit' value='set O' id='ionlywantod' />"); }); </script> <script type="text/javascript"> var localSearchBH193HG = new GlocalSearch(); localSearchBH193HG.execute("BH19 3HG, UK"); localSearchBH193HG.setSearchCompleteCallback(null, function() { map.addOverlay(createMarker(new GLatLng(localSearchBH193HG.results[0].lat,localSearchBH193HG.results[0].lng),'<h2>O Venue 1</h2>')); }); </script> <script type="text/javascript"> var localSearchSY79LT = new GlocalSearch(); localSearchSY79LT.execute("SY7 9LT, UK"); localSearchSY79LT.setSearchCompleteCallback(null, function() { map.addOverlay(createMarker(new GLatLng(localSearchSY79LT.results[0].lat,localSearchSY79LT.results[0].lng),'<h2>O Venue 2</h2>')); }); </script> <script type="text/javascript"> var localSearchRG46UT = new GlocalSearch(); localSearchRG46UT.execute("RG4 6UT, UK"); localSearchRG46UT.setSearchCompleteCallback(null, function() { map.addOverlay(createMarker2(new GLatLng(localSearchRG46UT.results[0].lat,localSearchRG46UT.results[0].lng),'<h2>E Venue 1</h2>')); }); </script> <script type="text/javascript"> var localSearchPE36GA = new GlocalSearch(); localSearchPE36GA.execute("PE3 6GA, UK"); localSearchPE36GA.setSearchCompleteCallback(null, function() { map.addOverlay(createMarker2(new GLatLng(localSearchPE36GA.results[0].lat,localSearchPE36GA.results[0].lng),'<h2>E Venue 2</h2>')); }); </script> </body> </html> I'm using JavaScript (rssplayer.js) to display a feed from a Blogger blog. I want the feed to be displayed as plain text without the hyperlink to the original posts. Does anyone know how to do this? Thanks rssplayer: http://www.javascriptkit.com/dhtmltu...jaxfeed3.shtml Here's the code in my page: Code: <script type="text/javascript"> //USAGE SYNTAX: new rssdisplayer("divid", "rssurl", numberofitems, "displayoptions") new rssdisplayer("rssdiv", "http://jms8bscience-assignments.blogspot.com/feeds/posts/default?alt=rss", 6, "")</script> Here's the code for the rssdisplayer.js Code: google.load("feeds", "1") //Load Google Ajax Feed API (version 1) function rssdisplayer(divid, url, feedlimit, showoptions){ this.showoptions=showoptions || "" //get string of options to show ("date" and/or "description") var feedpointer=new google.feeds.Feed(url) //create new instance of Google Ajax Feed API feedpointer.setNumEntries(feedlimit) //set number of items to display document.write('<div id="'+divid+'">Loading feed...</div>') this.feedcontainer=document.getElementById(divid) var displayer=this feedpointer.load(function(r){displayer.formatoutput(r)}) //call Feed.load() to retrieve and output RSS feed } rssdisplayer.prototype.formatdate=function(datestr){ var itemdate=new Date(datestr) return "<span style='color:gray; font-size: 90%'>"+itemdate.toLocaleString()+"</span>" } rssdisplayer.prototype.formatoutput=function(result){ if (!result.error){ //if RSS feed successfully fetched var thefeeds=result.feed.entries //get all feed entries as a JSON array var rssoutput="<ul>" for (var i=0; i<thefeeds.length; i++){ //loop through entries var itemtitle="<a href=\"" + thefeeds[i].link + "\">" + thefeeds[i].title + "</a>" var itemdate=/date/i.test(this.showoptions)? this.formatdate(thefeeds[i].publishedDate) : "" var itemdescription=/description/i.test(this.showoptions)? "<br />"+thefeeds[i].content : "" rssoutput+="<li>" + itemtitle + " " + itemdate + itemdescription + "</li>" } rssoutput+="</ul>" this.feedcontainer.innerHTML=rssoutput } else //else, output error alert("Error fetching feeds: "+result.error.message) } //USAGE SYNTAX: new rssdisplayer("divid", "rssurl", numberofitems, "displayoptions") //new rssdisplayer("adiv", "http://www.cssdrive.com/index.php/news/rss_2.0/", 5, "date, description") I have a page with a GoogleMap with a GoogleBar and I would like the GoogleBar to appear with something written in it already and to have that search executed. In other words, I would like to "write something to the GoogleBar and press Enter" automatically as soon as the map loads. How can I do this? btw: By GoogleBar, I mean the search bar that appears on the map after using the enableGoogleBar() function. Can the Google API replace scraping? You can get blocked by Google if you scrape, but can you get the same info from the Google API at no risk?
Hi All I have a xml string located in a hidden textbox that i need to parse how do i get it into a xml object I thought nievly i could xmlDoc = document.getElementById("XML").value alert(xmlDoc.getElementsByTagName("SupplMets")[0]); document.write("<table border='1'>"); but obviously i need to do some more work to get it into an xml object ...any ideas the end goal here is to get the data in the xml into a table here is what the xml string looks like <SupplMets TumorSupplementalId="272341"><SupplMet TumorSupplMetsId="109130" SiteOfMetastasis="C020" DateOfMetastasis="20010101" MetastasisIdType="" MetastasisEliminated="" MetastasisSD="02-003710" /></SupplMets> Anyone that can help on this one it would be greatly appreciated... I need to make a form parses a result from column 1 of txt/csv file that has 7 columns. Column 1 is pay, column 2-7 are how many and the associated rows are the answers. In short 1 2 3 4 5 6 700 50 55 62 75 80 99 so if the customer enters i make 700 and i need 2 the result would be 55 as the output. Any idea on how to make that work with javascript? if (pay <=700 && widgets = 2) { document.write(55) elseif (pay <=700 && widgets = 1) document.write(50) is this doable and is it the easiest way to accomplish this? I'm trying to parse out location data from XML that is passed back from Google. It currently parses the data correctly, the problem is that it grabs all of the matching tags, instead of just the first results set. Here's an example of the output. Here's the code I'm using to achieve this: Code: function(){ var url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=NewBrunswick,NJ&sensor=false'; $.ajax({url: 'proxy2.php?url='+url, type: "GET", dataType: "text", success: function ($data) {$data = $($data); lat = ($data.find('geometry').find('location').find('lat').text()); long = ($data.find('geometry').find('location').find('lng').text()); }});}); How would I change it so that it only grabs the data from the first set of results? hi, I am a newbie. Using Java script, I need to open and read CSV file. I need to read the third column values and store in an array. Please help me regarding this. Thanks, Hanumanth. I'm trying to work with XML DOM for the first time as I need to grab a value from a SOAP request. I've been following this: http://www.w3schools.com/xml/xml_parser.asp, which says modern browsers won't parse xml files from another server for security reasons. How would I got about doing this then? I've been using the price of crude oil as an example (http://www.google.com/ig/api?stock=OIL) and want code portable enough to put on something like Tumblr, so I don't think I can actually save the file locally first. Any ideas? Thanks, Zach Hey, Im fairly new to javascript but I am an experianced php programmer. I have been parsing XML information using php, but my CPU usage has been too high recently due to this. I am trying to convert my scripts to javascript, but I am unsure how I can do this using javascript. I think that if I get started off, the rest will be easy. One of my XML files is located at Code: http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=bbcradio1&api_key=c910b0bc1e2d4e64964ebcd2d69c255c&limit=500 Basically I have been trying to grab the Name, Artist and large image of the most recent <track>. Any help would be greatly appreciated and linked too on my website . Tim I'm developing a DHTML based Flashcard app that will work using firefox (MiniMo on Mobile Devices). It's working fine (reads and writes datafile to and from the local disk). However, when i start reviewing the flashcards, it seems to have some parsing issues. Do explain more about the data file, it is a 3 record CSV file with 3 catagories: ChineseCharacter, PinYin, English For some reason or another, i can figure out how to correctly pars out and put the correct data in the corresponding Data Arrays. I would like to get this program working as soon as i can, i plan to use it to study for the HSK test (Chinese proficiency test). I'm supposed to take it in about 4 months. - yes im cramming here's my code: Code: <html> <head> <script language="javascript"> // Set Global Variables var ChineseCard = new Array(); var PinYinCard = new Array(); var EnglishCard = new Array(); var Records = new Array(); var Know = 0; var DontKnow = 0; var CurrentCard = 0; var NumberOfCards = 0; var DataFile = "C:" + String.fromCharCode(92) + "FlashCard.txt"; var Delimeter = ","; function init() { document.getElementById("FlashCardPlayer").style.visibility = "hidden"; document.getElementById("FlashCardEditor").style.visibility = "hidden"; document.getElementById("MainMenu").style.visibility = "visible"; } function ShowPlayer() { document.getElementById("FlashCardPlayer").style.visibility = "visible"; document.getElementById("MainMenu").style.visibility = "hidden"; document.getElementById("FlashCardEditor").style.visibility = "hidden"; LoadFlashCard(); } function ShowEditor() { document.getElementById("FlashCardEditor").style.visibility = "visible"; document.getElementById("FlashCardPlayer").style.visibility = "hidden"; document.getElementById("MainMenu").style.visibility = "hidden"; } function ShowMain() { document.getElementById("MainMenu").style.visibility = "visible"; document.getElementById("FlashCardPlayer").style.visibility = "hidden"; document.getElementById("FlashCardEditor").style.visibility = "hidden"; } function ClickShowPinYin() { document.getElementById("PinYin").value = PinYinCard[CurrentCard]; } function ClickShowEnglish() { document.getElementById("English").value = EnglishCard[CurrentCard]; } function ClickKnow() { Know = Know + 1; if(CurrentCard == NumberOfCards) { // Display the score alert("You scored " + Know + " out of " + NumberOfCards); CurrentCard = 0; Know = 0; DontKnow = 0; // clear all textboxes and put index(0) chinese character into the chinese character textbox } CurrentCard = CurrentCard + 1; document.getElementById("PinYin").value = ""; document.getElementById("English").value = ""; document.getElementById("ChineseCharacter").value = ChineseCard[CurrentCard]; } function ClickDontKnow() { DontKnow = DontKnow + 1 if(CurrentCard == NumberOfCards) { // Display the score alert("You scored " + Know + " out of " + NumberOfCards); CurrentCard = 0; Know = 0; DontKnow = 0; // clear all textboxes and put index(0) chinese character into the chinese character textbox } CurrentCard = CurrentCard + 1; document.getElementById("PinYin").value = ""; document.getElementById("English").value = ""; document.getElementById("ChineseCharacter").value = ChineseCard[CurrentCard]; } function ClearEditor() { // Clear all the text boxes in the editor document.getElementById("EditChinese").value = ""; document.getElementById("EditPinYin").value = ""; document.getElementById("EditEnglish").value = ""; } function WriteData() { // Conicate the Record data var WriteData = document.getElementById("EditChinese").value + Delimeter + document.getElementById("EditPinYin").value + Delimeter + document.getElementById("EditEnglish").value + "\r"; // Load the data file's current contents var OldData = LoadFromDisk(DataFile); if (OldData == null) { var WriteDataUTF8 = utf8Encode(WriteData); // The file was blank, so don't try to append null content data SaveToDisk(DataFile, WriteDataUTF8 + "\n"); } else { var OldDataUTF8 = utf8Decode(OldData); var AppendData = OldDataUTF8 + WriteData + "\n"; var UTF8data = utf8Encode(AppendData) // Write the data to the file SaveToDisk(DataFile, UTF8data); } // Clear the TextBoxes to prepare for the next entry ClearEditor(); } function LoadFlashCard() { // Load the FlashCard Information from the DataFile into the Arrays var LoadData = LoadFromDisk(DataFile); // Convert the Datafile from UTF8 to ASCII var LoadDataUTF8 = utf8Decode(LoadData); Records = LoadDataUTF8.split(Delimeter); // Load the Elements in to the ChineseText, PinYin, and English Arrays NumberOfCards = (Records.length -1) / 2; NumberOfRecords = NumberOfCards * 3; // Load the Chinese Characters var Ptr = 0; for (var x = 0; x < NumberOfRecords; x = x + 3) { ChineseCard[Ptr] = Records[x]; Ptr++; } Ptr = 0; // Load the PinYin for (var x = 1; x < NumberOfRecords; x = x + 3) { PinYinCard[Ptr] = Records[x]; Ptr++; } Ptr = 0; // Load the English for (var x = 2; x < NumberOfRecords; x = x + 3) { EnglishCard[Ptr] = Records[x]; Ptr++; } alert(ChineseCard[1]); alert(PinYinCard[1]); alert(EnglishCard[1]); } function SaveToDisk(FileName, Content) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Permission to save file was denied."); } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( FileName ); if ( file.exists() == false ) { file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream ); outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); var output = Content; var result = outputStream.write( output, output.length ); outputStream.close(); } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } // ***************** The following are the functions for UTF8 *************************** // if these are removed or modified in any way, the foreign language characters might not display correctly or at all // Use utf8Encode(str) to Encode data to UTF8 format // Use utf8Decode(utf8Str) to Decode data to ASCII format //an alias of String.fromCharCode function chr(code) { return String.fromCharCode(code); } //returns utf8 encoded charachter of a unicode value. //code must be a number indicating the Unicode value. //returned value is a string between 1 and 4 charachters. function code2utf(code) { if (code < 128) return chr(code); if (code < 2048) return chr(192+(code>>6)) + chr(128+(code&63)); if (code < 65536) return chr(224+(code>>12)) + chr(128+((code>>6)&63)) + chr(128+(code&63)); if (code < 2097152) return chr(240+(code>>18)) + chr(128+((code>>12)&63)) + chr(128+((code>>6)&63)) + chr(128+(code&63)); } //it is a private function for internal use in utf8Encode function function _utf8Encode(str) { var utf8str = new Array(); for (var i=0; i<str.length; i++) { utf8str[i] = code2utf(str.charCodeAt(i)); } return utf8str.join(''); } //Encodes a unicode string to UTF8 format. function utf8Encode(str) { var utf8str = new Array(); var pos,j = 0; var tmpStr = ''; while ((pos = str.search(/[^\x00-\x7F]/)) != -1) { tmpStr = str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0]; utf8str[j++] = str.substr(0, pos); utf8str[j++] = _utf8Encode(tmpStr); str = str.substr(pos + tmpStr.length); } utf8str[j++] = str; return utf8str.join(''); } //it is a private function for internal use in utf8Decode function function _utf8Decode(utf8str) { var str = new Array(); var code,code2,code3,code4,j = 0; for (var i=0; i<utf8str.length; ) { code = utf8str.charCodeAt(i++); if (code > 127) code2 = utf8str.charCodeAt(i++); if (code > 223) code3 = utf8str.charCodeAt(i++); if (code > 239) code4 = utf8str.charCodeAt(i++); if (code < 128) str[j++]= chr(code); else if (code < 224) str[j++] = chr(((code-192)<<6) + (code2-128)); else if (code < 240) str[j++] = chr(((code-224)<<12) + ((code2-128)<<6) + (code3-128)); else str[j++] = chr(((code-240)<<18) + ((code2-128)<<12) + ((code3-128)<<6) + (code4-128)); } return str.join(''); } //Decodes a UTF8 formated string function utf8Decode(utf8str) { var str = new Array(); var pos = 0; var tmpStr = ''; var j=0; while ((pos = utf8str.search(/[^\x00-\x7F]/)) != -1) { tmpStr = utf8str.match(/([^\x00-\x7F]+[\x00-\x7F]{0,10})+/)[0]; str[j++]= utf8str.substr(0, pos) + _utf8Decode(tmpStr); utf8str = utf8str.substr(pos + tmpStr.length); } str[j++] = utf8str; return str.join(''); } </script> </head> <body onload="init()"> <!-- ***************************************** Flash Card Player ***************************************** --> <div id="FlashCardPlayer" style="position: absolute; left: 0px; top: 0px;" > <input id="ChineseCharacter" type="textbox" style="position: absolute; left: 75px; top: 5px; width: 100px; height: 100px; font-size: 35px;"> <input id="PinYin" type="textbox" style="position: absolute; left: 5px; top: 110px; width: 225px;" > <input id="English" type="textbox" style="position: absolute; left: 5px; top: 135px; width: 225px;"> <input type="button" value="Know" style="position: absolute; left: 5px; top: 170px; width: 100px; height: 30px;" onclick="ClickKnow();"> <input type="button" value="Dont Know" style="position: absolute; left: 125px; top: 170px; width: 100px; height: 30px;" onclick="ClickDontKnow();"> <input type="button" value="PinYin" style="position: absolute; left: 5px; top: 210px; width: 100px; height: 30px;" onclick="ClickShowPinYin();"> <input type="button" value="English" style="position: absolute; left: 125px; top: 210px; width: 100px; height: 30px;" onclick="ClickShowEnglish();"> <a href="" style="position: absolute; left:10px; top: 245px;" onclick="ShowMain();">Home</a> </div> <!-- ****************************************** Flashcard Editor ****************************************** --> <div id="FlashCardEditor" style="position: absolute; left: 0px; top: 0px;"> <input id="EditChinese" style="position: absolute; left: 75px; top: 5px; width: 100px; height: 100px; font-size: 35px;" type="textbox"> <input id="EditPinYin" style="position:absolute; left: 5px; top: 110px; width: 225px;" type="textbox"> <input id="EditEnglish" style="position:absolute; left: 5px; top: 135px; width: 225px;" type="textbox"> <input id="EditClearTextButton" value="Clear" style="position:absolute; left: 5px; top: 180px; width: 100px; height: 30px;" onclick="ClearEditor();" type="button"> <input name="EditOKButton" value="OK" style="position: absolute; left: 125px; top: 180px; width: 100px; height: 30px;" onclick="WriteData();" type="button"> <a href="" style="position: absolute; left:10px; top: 225px;" onclick="javascript:Alert("*sigh* i'm getting to it!");">New</a> <a href="" style="position: absolute; left:10px; top: 245px;" onclick="ShowMain();">Home</a> <br> </div> <!-- ****************************************** Define the Layer for the Main menu ****************************************** --> <div id="MainMenu" style="position: absolute; left: 0px; top: 0px;"> These are the instructions for the Flashcard App. In the future, there should be a score board and a selection of word lists and other such things. However, it's blank for now until i finish this app :) <input value="Study Flashcards" style="position: absolute; left: 50px; top: 170px; width: 120px; height: 30px;" onclick="javascript:ShowPlayer();" type="button"> <input value="Edit Flashcards" style="position: absolute; left: 50px; top: 210px; width: 120px; height: 30px;" onclick="ShowEditor();" type="button"> </div> </body> </html> I have been able to parse a JSON feed before but forwhatever reason this time around I am having a hell of a time getting it working. Here is where I am at right now. So far the script dosn't output anything. Code: <table width="100%" border="0" cellspacing="0" cellpadding="10"> <script> xhttp=new XMLHttpRequest(); xhttp.open("GET","http://biz104.inmotionhosting.com/~cox7co5/api/get_category_posts/?id=5",false); xhttp.send(""); json_data=xhttp.responseText; var parsed_data = eval('('+json_data+')'); var slug="stuff" for (i=0;i<parsed_data.count;i++) { document.write("<tr><td><a href=\"#\" class=\"showlist\">"+parsed_data.posts[i].title+"</a></td><tr>"); } </script> </table> Hello, I'm trying to parse my data from an xml file now and print it out on the page based on date from my existing code. I have that working, with each item formatted the same way on the page What I'd like to do now is alter it a bit to make the most recent (the item listed on the top of the page) formatted differently and the rest of them as it is now. Something like - (if 1st <li> then build html like this else build html like that) I hope this makes sense. Code: <?xml version="1.0" encoding="utf-8" ?> <books> <book title="CSS Mastery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/css.jpg"> <description> 08/01/2010 - Content </description> </book> <book title="Professional ASP.NET" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/asp.jpg"> <description> 08/02/2010 - Content </description> </book> <book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg"> <description> 08/03/2010 - Content </description> </book> <book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg"> <description> 08/04/2010 - Content </description> </book> <book title="Learning jQuery" imageurl="http://cdn.net.tutsplus.com/045_LoadXMLWithJquery/images/lj.jpg"> <description> 08/05/2010 - Content </description> </book> </books> Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Load XML With jQuery</title> <script src="jquery-1.2.6.js" type="text/javascript"></script> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function() { /*Gets current date*/ var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var date = new Date(); /*var curr_date = d.getDate();*/ var curr_date = 3; var curr_month = date.getMonth(); var curr_year = date.getFullYear(); $.get('myData.xml', function(d){ /* $('body').append('<h1> Title</h1>');*/ $('#col-a').append('<ul id="tips"/>'); $(d).find('book').each(function(){ var $book = $(this); var title = $book.attr("title"); var description = $book.find('description').text(); var imageurl = $book.attr('imageurl'); var html = '<li class="tipItem" style="list-style:none;display: none; li">'; html += '<img class="bookImage" alt="" src="' + imageurl + '" /> '; html += '<p class="title">' + title + '</p>'; html += '<p> ' + description + '</p>' ; html += '</li>'; $('ul').append($(html)); }); var tips = $('#tips .tipItem'); tips.each(function(i) { if (curr_month == 8 && curr_date <= i){ $(this).hide(); } else { $(this).show(); } }); tips = $.makeArray(tips); tips.reverse(); $(tips).appendTo(document.getElementById('tips') ); }); }); </script> </head> <body> <div id="col-a"></div> </body> </html> |