Posts by bfavaretto • 64,705 points
902 posts
-
3
votes3
answers941
viewsA: Encapsulation in Javascript
As Maniero said, it depends on your security concept. Declaring the variable within a function prevents others from scripts read or change its value. However, it does not prevent a person, armed…
javascriptanswered bfavaretto 64,705 -
3
votes3
answers125
viewsA: Search List(Of String) - Case insensitive
The problems I see in this code: The method Find will return an item from the list, therefore a String. But you declared v_contains like Boolean. The predicate of Find would need to return a boolean…
-
12
votes4
answers489
viewsA: How does jQuery make parameters dynamic?
You do not need to name any function parameter. When it is invoked, all received arguments are available in the object arguments. You can examine what is there and treat it the way it is most…
-
2
votes2
answers579
viewsA: How to pass an array of php Stdclass objects to a JS variable using $.ajax() jquery
Convert the object to JSON when responding to jQuery: <?php $o1 = new stdClass; $o1->post_id = 140; $o2 = new stdClass; $o2->post_id = 141; $arr = array($o1, $o2); echo json_encode($arr);…
-
2
votes1
answer85
viewsA: How to change the value of the variable in Factory?
I don’t know if I understand the question, but just as you have methods to get and increment this variable, you can create another one to define its value (a Setter): app.factory('testFactory',…
-
2
votes4
answers173
viewsA: Javascript PHP sprintf equivalent
In Ecmascript 6 (ES6), the latest version of the Javascript specification, there are strings template, that allow for something similar: var a = 5; var b = 10; console.log(`Fifteen is ${a + b}…
-
3
votes1
answer217
viewsA: How to make a denial condition with instanceof, without affecting the order of precedence?
If you look at PHP operator precedence table, will see that the instanceof takes precedence over !. This means that, in an expression that includes both, the instanceof is applied before. Therefore…
-
2
votes1
answer1437
viewsA: Load JSON via Angularjs
Try: app.controller('TelaController', ['$http', function($http){ this.user = $http.jsonp('info.json'); }]); (I’m in no condition to test now, maybe I’m wrong)…
-
14
votes2
answers7903
viewsA: What is the difference between offset(). top and position(). top in jQuery?
The difference is that the offset is related to the document, while the position is relative to the nearest positioned ancestor (*). For example: var b = $('#b'); var offsetTop = b.offset().top; var…
jqueryanswered bfavaretto 64,705 -
2
votes3
answers66
viewsA: How do I use my jQuery extension in the on function?
In fact the answer of Emir Marques hit the beam. The way is yes the trigger, which is necessary to trigger the event. Any event fired with trigger can be captured with on. Thus: (function ( $ ) {…
jqueryanswered bfavaretto 64,705 -
8
votes1
answer439
viewsA: With doing an iterator/Generator in javascript?
The specification Ecmascript 6 added Iterators and generators to the hard core of language, but today (end of 2015) there is still limitations of browser support. I will explain how it works/will…
-
3
votes1
answer155
viewsA: Variable return in javascript = Undefined
The variables tempo and veloc are elements, not values. So it should be: var distancia = parseInt(tempo.value) * parseInt(veloc.value); Already distancia and litros are values, and not elements. So…
javascriptanswered bfavaretto 64,705 -
6
votes3
answers857
viewsA: Javascript Method Overload Function
To eduardo’s response explains what is happening, and I will try to illustrate. Each time addMethod is called, she keeps as old whatever is in object[name], creates a new function, and stores it in…
-
4
votes2
answers34
viewsA: Opacity in Pseudo-Element and Parent
If I understand your goal correctly, one of the ways is to use the triangles trick: h4 { font-size: 21px; font-family: "Verdana"; color: #FFF; background-color: rgba(248, 149, 32, 0.8); padding: 5px…
-
3
votes2
answers81
viewsA: What’s the risk with this intel?
Yes, there is a risk of someone deleting your entire bank when exploiting this vulnerability. The solution does not necessarily go through PDO, but through Prepared statements, that you can use with…
-
2
votes4
answers6197
viewsA: Resume all values in stdClass Object Array
It seems that you need to create a new array only with this data. It can be manually, using a loop, as in André Baill’s answer, or using the function array_map, thus: function descricoes($item) {…
phpanswered bfavaretto 64,705 -
4
votes2
answers460
viewsA: How to replace Eval() with another expression
I would do so: var v_num_seq_cobranca = form01['num_seq_cobranca_' + intI].value;
javascriptanswered bfavaretto 64,705 -
8
votes1
answer375
viewsA: How $.when() and . then() aligned works
This code is based on promises (Promises, implemented in jQuery as $.Deferred). A promise is an object that represents the result of a asynchronous operation (the most common case is an Ajax…
-
2
votes1
answer30
viewsA: Prolog-related error on a. xhtml page using Netbeans
The error is not talking about the Prolog language, but about the prologue XML, which is the snippet where you declare that the document is in XML, before the root node and the content itself.…
-
3
votes2
answers1636
viewsA: Why do we have to use ? > <?php when we use Eval in the content of a php script?
The eval PHP expects to receive a snippet of code valid, but allows you to switch to "HTML mode". For example, this excerpt, adapted from an example of the manual eval('echo "In PHP mode!"; ?>In…
-
5
votes2
answers7297
viewsA: How to duplicate a MYSQL database?
I usually do this outside of phpMyAdmin, using mysqldump in the shell. First you dump the current base: mysqldump -R --user=usuario --password=senha nomedabase > arquivo.sql The -R is to include…
-
5
votes1
answer192
viewsA: Select, by quantity, items that match conditions
If I understand correctly, you will need a subquery. I got a solution using ROW_NUMBER, which numbers the lines found. The PARTITION BY is being used to reset the count for each table row…
-
5
votes2
answers314
viewsA: How to omit a specific ng-options item?
You can apply a filter by object matching, denying this specific id, thus: <select ng-model="information" ng-options="value.id as value.name for value in information | filter: {id: '!301'}">…
-
11
votes3
answers16866
viewsA: How to check Undefined correctly in Javascript
The two checks you mentioned serve for different things. 1. Variables not declared If a variable has not been declared, with var variável = ..., you can’t use it in equality comparisons like…
-
31
votes2
answers1922
viewsA: Why do they say that recursive setTimeout is better than setInterval?
I’m always suspicious of "X is better than Y" type statements, or "X is evil". They usually have foundation, but should not be followed blindly. The ideal is to understand why these statements…
-
3
votes2
answers97
viewsA: Generated list with JSON data
The error starts on this line: for(state in states) { The command for..in was created to iterate object keys, not array content. It’s okay that JS arrays are objects, only you’re iterating the keys…
-
12
votes6
answers47809
viewsA: How to search for a particular object within an array?
If you have an object reference, you can use the indexOf same, which strives for equality (two references are equal only if they point to the same object): // Não se esqueça de usar var! var arr =…
-
1
votes3
answers154
viewsA: There is some significant difference between the IMG tag and INPUT IMAGE
There are two main differences: The <input type="image"> acts as a button, and will submit the form to which it belongs when clicked. By clicking on a <input type="image">, shall be…
htmlanswered bfavaretto 64,705 -
5
votes2
answers765
viewsA: Get script from a DIV with JS
If by "script" you mean get all the HTML inside the div, do so: var form = document.getElementById('form'); var conteudo = form.innerHTML; alert(conteudo); <div id="form"> <div…
-
4
votes2
answers59
viewsA: Modal window does not work correctly by clicking YES
You only set what needs to be done at the YES click when you click #modalLogout. I did not understand the intention of this "outside" part of the code, so it would be enough to define the YES click…
jqueryanswered bfavaretto 64,705 -
15
votes3
answers181
viewsA: Why in Javascript, 7 (a number) is not an instance of Number?
In Javascript, there are primitive types for String, Number and Boolean (besides Object and of the types Null and Undefined, which only have one instance each). So, primitive values like the ones in…
javascriptanswered bfavaretto 64,705 -
2
votes2
answers910
viewsA: How to select an element in a jQuery selection
In that case you use filter: var $els = $('elementos'); var $el = $els.filter('.active'); Now, if you sail with next and prev from the $el, will be sailing for his brothers in the DOM, not in your…
jqueryanswered bfavaretto 64,705 -
3
votes1
answer578
viewsA: Filter no ng-repeat filter the parameter I passed in get
In your controller, you have access to route parameters via $routeParams. So it’s possible to store this as a model, and use its reference in the filter:…
-
4
votes1
answer1324
viewsA: Unreachable Statement
The error is here: public boolean onContextItemSelected(MenuItem item) { return super.onContextItemSelected(item); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)…
-
3
votes2
answers606
viewsA: Select category and subcategory within the same table
As there are only two levels, just one JOIN of the table with itself (a self John): SELECT modulo.*, principal.idModulo AS idModuloBase, principal.modulo AS moduloBase, principal.pasta AS pastaBase…
-
10
votes1
answer3099
viewsA: Uncaught Syntaxerror: Unexpected token this
In this code there are several function expressions within a constructor function (which has also been declared as expression). The structure of this code is more or less like this: var Construtor =…
-
0
votes1
answer160
viewsA: Change label text while running a loop on the server
I know it wasn’t the best solution, but I needed to be fast and as I had already turned the google and nothing helped I decided to do this way. On the processing screen, where you have the loop, on…
-
4
votes1
answer1545
viewsA: Uncaught Rangeerror: Maximum call stack size exceeded
The mistake is because you are calling the function within itself, endlessly, here: rafID = window.requestAnimationFrame( updateAnalysers("analyser") ); In fact the requestAnimationFrame expects to…
javascriptanswered bfavaretto 64,705 -
8
votes1
answer110
viewsA: Toggle javascript functions
The object also has a method pause, and a property paused to check if it is already paused. So you can do so: var sng1 = document.getElementById("audio1"); var bt1 = document.getElementById("btn1");…
-
5
votes1
answer396
viewsA: Insert an Array, regardless of the amount of $_POST
If I understand correctly, you want to insert several rows in the table. In Mysql you can do so: INSERT INTO tabela (caminho) VALUES ('...'), ('...'), ('...'); To build this query in PHP,…
-
3
votes4
answers646
viewsA: Perform function by clicking except on specific item with jQuery
Well, you already have several answers, but I’m going to propose another method: $('.teste').click(function(e) { return !(e.target == this); }); .teste { background: yellow; padding: 20px; } <div…
-
7
votes3
answers4229
viewsA: Check the running time of a Javascript function
As Mr Angelo said, in modern browsers you can measure the elapsed time accurately by fractions of milliseconds using the object performance. The logic is the same as the other answers, but not to be…
-
3
votes2
answers1416
viewsA: Break txt file into blocks, and each block into rows
The white space between the blocks are two line breaks, ie, "\n\n". Then you can break the blocks so (considering the result of the file_get_contents is in $dados): $blocos = explode("\n\n",…
-
4
votes2
answers219
viewsA: Stop loop in function inside another
If the goal is to break the loop if you enter the if of teste3, not enough a return inside that function. The return would need to be inside the function teste, because the functions do not return…
node.jsanswered bfavaretto 64,705 -
2
votes1
answer68
viewsA: Parse error on Less, says my class/mixin is not defined
That one .vertical(#f5f5f5, #f9f9f9) is what Less calls mixin prametric, which is like a function that gets parameters. It needs to be declared somewhere. I imagine you’re looking for something like…
-
4
votes1
answer388
viewsA: Error importing Dynamic Json via Angularjs
Looks like you’re mixing up some stuff from the Angular documentation, I’ll try to explain the problems: This url you are using returns JSONP to bypass the access restriction policy for another…
-
1
votes1
answer326
viewsA: How to pass an Array to Angularjs?
You need to serialize the array as JSON, which is what Angular is waiting to receive: <?php $dados = array ( array ( 'nome' => 'Paulo', 'idade' => 15, ), array ( 'nome' => 'João',…
-
4
votes1
answer569
viewsA: jQuery ajax, asynchronous encapsulation
The classic way to solve this is to pass a callback, or use the promise itself returned by Ajax. I will show examples. Passing a callback custom.ajax=function(obj,funcao,view, callback){ // FUNÇÃO…
-
1
votes1
answer163
viewsA: Angular in PHP page read an API generated in php
The main problem is that this data you are trying to access is not available via AJAX from another domain. The server of that site (flip) would need to be configured to allow access to cross-origin.…
-
1
votes1
answer979
viewsA: Package installed with npm is not available at command prompt
To be able to access from anywhere, you would need to have done a "global" installation of the module: npm install -g hexo This works if the location where npm installs the global modules is…
node.jsanswered bfavaretto 64,705