5

Two different things here: there is a function and there is a function call In JavaScript, functions are so-called first-class objects, and what this means is that they, like other values, can be passed to or returned by other functions. So it is possible for a JavaScript function to take another function as an argument (or return another function), as it'...


4

what exactly a markup language is and how it is different from programming language and scripting languages in layman's terms, a markup language is a set of markup tags. according to this: A markup language is a set of tags and/or a set of rules for creating tags that can be embedded in digital text to provide additional information about the text ...


4

Had the same trouble. Fix it with 'var' before 'marker = new...'. Else you overwrite the same variable each time.


3

Replaced with: $.getJSON("articles.php?geo="+place.postal_code) .done(function(data, textStatus, jqXHR) { more code } and now call is returning data. Still not sure why previous code didn't run, but now project works!


3

Thats Really simple, in Google Chrome, simply right click on the page(if your'e using a mac, its cmd-click) without selecting any text, and you shall see a menu bar, like the one in the photo below- Here, click "View Page Source" to see it. Happy Coding!


2

I just figured it out! The reload was due to the very nature of onsubmit. When I changed it to onClick, I had no issues!


2

An elegant way to check if a certain variable was declared (or not) is the in operator. The check if a passenger is a freshman can be done like this: // check for freshmen if (!(PASSENGERS[i].house in HOUSES)) { $("#announcements").html("No freshmen, sorry. Blame the pset specs."); } PASSENGERS[i].house in HOUSES returns true if a variable of the name ...


2

How does the computer recognize that those few lines inside a JavaScript file is actually html and not JavaScript codes? It doesn't. It's not javascript or html to the function, it's data. When it is (finally) rendered by the browser, it is "recognized" as html. rather than writing part of the program in python and part in JavaScript, have ...


2

One problem is this syntax markers += marker;. That does not add an element to an array in js. The array method push adds elements to an array. Another problem is here marker.addListener(map, "click", function(). That's not the correct syntax to add a listener to a marker (extraneous argument). Review the api doc here. Once you get those things sorted, ...


2

You are always setting myLatLang here var myLatlng = new google.maps.LatLng(42.3770, -71.1256); // Cambridge, Massachussets, so all the markers will go "there". The argument place is the result of the SELECT query in the update route in application.py, so you probably want the lat/lang from the place dictionary. Instead of doing this: var myLatlng = new ...


2

.focus(handler) is short for .on("focus", handler), and installs an event listener, in your case, handler is an anonymous function declared with one parameter. Those handlers, when called, receive an event object. It has some properties and methods that might be interesting, in my opinion some of the most valuable are target, preventDefault, and ...


2

Thanks to @DinoCoderSaurus for your help - basically the problem was that I was trying to instantiate a MarkerClusterer for each individual marker that was added to the array. The solution was to delete the line markerCluster = new MarkerClusterer(map, markers, {imagePath: '/static/markers/m'}); from the addMarker() function; and instead have it run once ...


2

JavaScript $.get is asynchronous. It triggers an HTTP request and returns. The code meant to prevent submission runs after submission is processed, and therefore can't prevent it. The preventDefault has to go into the submit handler, not the $.get callback, and would be called each time you try to submit, cancelling the submit attempt. Inside the get ...


1

A list of a list. Program expects a list of places. execute returns a list of rows. This return jsonify([placesMatches]) (specifically the []) nests placesMatches into another list.


1

I added this line service = new google.maps.places.PlacesService(map); to my pset8 and it gave this message TypeError: google.maps.places is undefined in the browser console. Internet search of the error turned up this stack post which says you need to add a libraries option to the Google API URL (more detail in the link). But wait, there's more! (5 hours ...


1

I'd change that to simply $.getJSON("/search", ....) with no reference to Flask.


1

The main issue I can see if you are making an Ajax request via JQuery's getJSON() method. This method makes a GET Request. Handling this in the POST section of your index function will cause the request to always "fall through" to the else: @app.route("/") @login_required def index(): if request.method == "POST": q = ...


1

Before you spend too much time researching this on the web, just look closely at the distribution code provided. If I recall correctly, you won't need to change the HTML or CSS files, just the JavaScript. Look at the code for the clearFeedback() function. Straight-up copy that into the giveFeedback() function, and edit it to fit the new context. If you ...


1

HTML codes don't need to be compiled to work. Here is a useful link: http://www.yourhtmlsource.com/starthere/whatishtml.html


1

Answers 1. Yes. The following function function addMarker(place) { // GPS coordinates for marker var latLng = new google.maps.LatLng(place.latitude, place.longitude); // Create marker var marker = new google.maps.Marker({ position: latLng, map: map, title: place.place_name, text: place.place_name, }...


1

You need to use /img/news2.jpg (notice the preceding slash) since img is a subdirectory of public (assuming that news2.jpg is stored in img). You should be able to do it in one line this way: icon: '/img/news2.png',. That worked for me.


1

It is an object method. See getJSON api doc especially The jqXHR Object section. This article on jQuery chaining explains why it looks like the methods are "not attached to an object".


1

Answer: showInfo expects marker and content as arguments, in that order. I was passing them in the wrong order. When you get an error like that, you have to go back and check every little thing!


1

First you need to think about time past. A common logical way to do this is as so: 1) User presses a key - set time of "now" to a variable lets say "start". 2) User stops typing - compare "now" to "start" to get time passed. You can use something like this for time: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/...


1

If you want to use the redirect() function provided in pset7 I'm not sure how, but in general you can do it like so: echo "<script type='text/javascript'> if (confirm('Want to redirect?')) { location.href = 'http://www.google.com/'; } </script>";


1

If you want to use the popup window for any browser you probably want to use javascript. The popup window you have above is called a confirmation box. Here is how to use it: function foo() { confirm("Message to be displayed"); } The above function should be inside a <script> tag. Then on your <input> tag with type="submit" also define the ...


1

when your browser requests and HTML page that has an <img> element, it extracts the link of the image (the value of the src attribute of that element) and makes a new HTTP request to get that image file, then renders it accordingly. browsers essentially know how to process and render images. data URIs enable you to minimize the number of HTTP requests ...


1

A button is an element that is intended to perform an action when clicked; a menu is an element that is intended to select an option when clicked. If you embed the menu in the button, they are sharing the same space on the screen, so that you cannot click the menu (to select an option) without simultaneously clicking the button (to perform an action). If you ...


1

The problem is caused when shuttle.seats[i] is equal to null as you're trying to set the name property of it to PASSENGERS[i]. In other words, there is no name property (or pretty much any other property) for an object whose value is null. You probably should do something like shuttle.seats[i] = passenger; where shuttle.seats[i] is that seat that you ...


1

This is the answer from Kareem's link. Please do not vote on this. I just want to take this answered question out of the unanswered list. There are actually several approaches to do this. Some require more overhead than others, and some are considered better than others. In no particular order: Use AJAX to get the data you need from the server. Echo the ...


Only top voted, non community-wiki answers of a minimum length are eligible