Posts by bfavaretto • 64,705 points
902 posts
-
4
votes1
answer97
viewsA: In which part of the application is it more appropriate to reorder an array (database, server application, client code)?
Take care of the ordering as soon as possible. In your case, this means in the database. taking into account memory consumption and data processing speed It is not possible to take this into account…
-
7
votes1
answer433
viewsA: Width of a <td> is not of last size
I don’t understand why using a table, apart from table patterns via CSS... If you really want to use table (if it’s to show tabular data, ok, otherwise do not recommend), use colspan="2" in the last…
-
7
votes3
answers183
viewsA: Echo returning wrong value
It was already clear from the other answers and comments that you need to isolate the mathematical operations with parentheses. As suggested by Sergio: $arr_4[] =…
phpanswered bfavaretto 64,705 -
6
votes1
answer241
viewsA: Inner Join between two tables
This one of yours JOIN will work only if the product has the same idQualityGate in all three columns you have for this (idQualityGate, idQualityGate2, idQualityGate3). Looks like you want one OR,…
-
4
votes3
answers194
viewsA: Why use float:left and display:inline at the same time?
Generally, floating elements have a display value implicitly defined as block. However, the case of list items is an exception. According to the specification, in CSS 2.1 is not defined if values…
-
2
votes1
answer520
viewsA: Function does not remove array elements
Your variables objp and objs in Javascript are not arrays, are strings. PHP will simply issue "Array()" for them. Your PHP would need to be like this: print("<SCRIPT language=javascript> objp…
-
4
votes4
answers23882
viewsA: How to create a permissions control system
The question is wide because there are many ways to implement a permissions control system. Even so, I will try to show one of the possible paths, in general lines. Permissions control takes into…
-
6
votes1
answer1854
viewsA: How to run a javascript function from a json file
Technically, this is not a function, as JSON does not contain functions. It is a string with the source code of a function inside. What you can do to run is to use the eval (worth reading the…
-
16
votes8
answers12405
viewsA: How to switch between true and false checked input?
I would use the following code: /* Não precisa de JavaScript! */ That is, no code! If your label already has the attribute for pointing to input, it is not necessary to use JS. The default behavior…
-
58
votes5
answers6116
viewsA: What is the difference between the functions var name = Function() and Function name()?
If you are in a hurry, better see examples scope visibility in Bacco’s response :) The main difference is of scope visibility, which Bacco demonstrated in the examples of his answer. To understand…
javascriptanswered bfavaretto 64,705 -
4
votes2
answers4048
viewsA: Return which of the query items are not in the table?
You could solve this by creating a temporary table with the searched values and do a LEFT JOIN with the system table searching for NULL in comparison. But it would have some simpler way to return…
-
1
votes1
answer95
viewsA: Javascript array for PHP
When you give inputs++ within the if, That doesn’t work, because inputs is a list of fields, not a number. If you want to count how many inputs are filled, you can create another variable for this:…
-
3
votes1
answer395
viewsA: Link sharing on Facebook
I get the impression that it is because the value passed (which is an entire URL) is not properly encoded for URL. Try: var link = "http://www.facebook.com/sharer.php?u=" +…
-
4
votes1
answer231
viewsA: Code prints twice but should print only once
If you are answering the first question with 1, is because your loop rotates once to zero, and again to one. You need to use < instead of <=: for(int i = 0; i < TAMANHO; i++) And for each…
javaanswered bfavaretto 64,705 -
4
votes4
answers2028
viewsA: Identifying common snippets in two PHP strings
I thought about an approach a little different from the others. I wanted to avoid nested loops, but I didn’t test if this has a positive impact on performance. It works that way: Creates an array of…
-
3
votes3
answers794
viewsA: Capture content to be pasted
The pasted content is in itself value field. So you can do so (worked on Chrome, not tested on other browsers): var input = $('input'); input.on("paste", function (evt) { input.val('huehue ' +…
-
13
votes1
answer20429
viewsA: XML file with no associated style information
Translation: This XML file appears to have no associated style information. The document tree is displayed below It means that XML gives no hint to the browser about how to display its content, and…
xmlanswered bfavaretto 64,705 -
4
votes5
answers5323
viewsA: How to center a div with position:Fixed?
If your browser gives support you can do it like this: left: calc(50% - 50px); http://jsfiddle.net/55d4vr5y/ That is, position the div on the left half the container width minus half the width of…
-
2
votes1
answer198
viewsA: Show menu with ng-click + ng-class
Just include overflow: hidden on your menu. It initially has zero width, but the content leaks and is always visible. Your class menu then it would look like this: .menu{ width:0px; height:400px;…
-
6
votes1
answer245
viewsA: Ajax response repeats that of another request and the page is not even the same
The problem is that you use a single Xmlhttprequest object. I may be wrong, but I think to fix just make your variable xmlhttp local (for she is a implicit global): function ajax(endereco, metodo,…
-
15
votes1
answer328
viewsA: How does the Javascript garbage collector work?
It seems that you already understood well how it works, but I will comment on each case. Simple variables If there is no further reference to the object, he may be eliminated: var obj = {foo:…
-
12
votes2
answers1344
viewsA: Quote problem when doing INSERT SQL
Single quotes should only be used in values. So they are ok in VALUES ('blabla'). Already in table names, columns and aliases, or you don’t use anything, or you use backticks `. These backticks are…
-
3
votes1
answer309
viewsA: How to get the position of an <Circle> element that is inside an SVG via Javascript?
The Circle position is defined by the attributes cx and cy. <svg> <circle cx="50" cy="50" r="15"></circle> </svg> var circulo = document.querySelector('circle');…
-
10
votes1
answer754
viewsA: $. getJSON does not record return on variables
The problem is that the getJSON is an operation asynchronous, which means that it is not completed immediately. The code that comes after the getJSON (which includes your console.log and the return…
-
50
votes3
answers8505
viewsQ: What is the semantic difference between <em> and <Strong>? Do they replace <i> and <b>?
They say the element <em> should be used for emphasis, and the <strong> for even more intense emphases. This seems rather confusing. When and why use each of them? And <i> and…
-
10
votes2
answers1472
viewsA: Discontinuation of the <center> tag
As HTML, CSS and Javascript/DOM were evolving, the "evangelists" of the web standards began to advocate a clearer separation of the responsibilities of each of these layers, seeking to mitigate the…
htmlanswered bfavaretto 64,705 -
12
votes2
answers87
viewsA: Error declaration of Javascript objects
Alternative to the Mukotoshi version, where all objects of this type would share the method (in its version, each has a copy of the method): function Pessoa(nome, idade){ this.nome = nome;…
javascriptanswered bfavaretto 64,705 -
8
votes3
answers657
viewsA: How to make the page load only after the return of getJSON?
Pass a callback to the getJSON: jQuery.getJSON(url, function(dados) { // aqui o json já carregou e pode ser acessado como "dados" });
-
8
votes3
answers181
viewsA: I have sets of variables storing different settings. How to use a specific set depending on the occasion?
You can use variable variables, but I find it extremely ugly and confusing: $dbL = "1"; $s_ipserver1 = "bla"; $servidor = 's_ipserver'. $dbL; echo $$servidor; // "bla"; It would be more elegant to…
phpanswered bfavaretto 64,705 -
8
votes2
answers145
viewsA: Number of repetitions per character
To carlospheric response solves the problem, but has an easier way to count: instead of the array, use an object as dictionary, with each character as key and the corresponding amount as value. For…
javascriptanswered bfavaretto 64,705 -
1
votes2
answers205
viewsA: SASS function does not work
You didn’t call the function. I believe the correct one would be: .my-module { width: cp(650px, 1000px); }
-
7
votes1
answer681
viewsA: How to compare 2 potentials
Use Math.pow to calculate power, and compare results. For example: var entrada = [2,2,3,3]; // confiando que entrada.length >= 4 if(Math.pow(entrada[0], entrada[1]) > Math.pow(entrada[2],…
javascriptanswered bfavaretto 64,705 -
6
votes2
answers207
viewsA: How to force the '.on("input")' method via script?
You came close in the fiddle: $("#textbox").trigger("input"); http://jsfiddle.net/Lyqu4s92/1/
-
4
votes1
answer1090
viewsA: Use of attr to apply edge color to LI
No, use the method .css() instead of the attr. For example: $('li').css('border-color', '#00ff00'); If the color comes from a data-attribute in your HTML, no problem. For example: <li id="sei-la"…
-
5
votes1
answer100
viewsA: Connections and management
Yes, if more than one variable points to the same object, they all need to receive null so that the memory occupied by the object is released. PHP maintains a reference count for the objects. When…
-
75
votes1
answer722
viewsA: Why (!+[]+[]+![]). length returns 9 in Javascript?
Step by step: +[] === 0 !+[] === true !+[]+[] === "true" (!+[]+[])+![] === (!+[]+[])+false === "truefalse" "truefalse".length === 9 It has several type coercions that ultimately cause this result.…
javascriptanswered bfavaretto 64,705 -
8
votes2
answers163
viewsA: What is differential inheritance?
Free translation of wikipedia article (so thin that we even suspect): Differential inheritance is a common inheritance model used in prototype-based programming languages such as Javascript, Io, and…
-
5
votes3
answers1211
viewsA: How to modify form fields if user input is invalid compared to regular expression with Jquery
In browsers with the proper support, you solve this by CSS: input:invalid { background: red; color: white; } http://jsfiddle.net/007go6vu/…
-
14
votes2
answers1064
viewsA: When to use Graceful Degradation and when to use Progressive Enhancement?
@utluiz is right when he says that technically there is no difference. The antagonism between the two terms (they are not technical, they are more for philosophies) today is not as strong as it once…
-
8
votes1
answer99
viewsA: Is there any way to Feature Detection for CSS?
Yes, you can do CSS Feature-Detection, both using Javascript and with pure CSS (in this case you have your own cross-browser support issues). By Javascript, you simply check the object style of an…
-
4
votes2
answers1260
viewsA: Restart script after load() function
Delegate the treatment of the event to an ancestor who is permanent on the page: $(document).ready(function() { $('.page-wrapper').on('click', '.submenu', function(event) { event.preventDefault();…
-
8
votes2
answers15096
viewsA: How to count the number of characters of the word that came from the first line of a text file?
The variable $f represents the file. The command fgets($f) reads the next line of the file (in your example, the first). So it makes no sense to try to measure $f, you need to measure fgets($f): $f…
-
2
votes1
answer176
viewsA: Measure distance between SVG polygon points
Assuming you already have coordinates in Javascript variables, just apply the Pythagorean theorem: var d = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); Applying to your HTML, you can do…
-
6
votes4
answers317
viewsA: Why are maps "faster" than arrays?
There are some incorrect things in your test: Leave the object definition and array out of the test, in the setup, so that the time of the declaration and assignment of value does not count in the…
-
3
votes1
answer118
viewsA: How to search and show data
If I understand correctly, you can do everything in a single query, no need to separate: SELECT peri.* /* substitua pela lista de campos que quer */ FROM sai_nota INNER JOIN peri ON peri.fk_nota =…
-
3
votes2
answers267
viewsA: Does replacing <a> with <span> cause problems in the page’s SEO?
It is wrong yes. This is not valid HTML, as the element span does not have the attribute href. I’m no SEO expert, but I’d say the chances of search engines ignoring your links are pretty high.…
-
1
votes2
answers117
viewsA: API Stackoverflow, "quota_max"
If you want all users, maybe it’s better download the data dump from the site via bittorrent. There, the full list of users will be available as an XML file.…
-
8
votes3
answers3244
viewsA: Calling a method from a Javascript class (OOP)
Reading the answer from Rui Pimentel, it occurred to me that you can create an instance within the function itself, if it is called without new. The practical consequence of this is that it does not…
-
10
votes2
answers7980
viewsA: What’s that "Mr-only" Bootstrap Twitter thing for?
The documentation says: Hide an element to all Devices except screen Readers That is to say: Hides an element for all devices except screen readers. Therefore, it is a way of presenting content that…
-
5
votes2
answers3226
viewsA: Run script in a <div>
Remove this part of the script, it is unnecessary: myFunction(); // Fails because it hasn't loaded from my.js yet. window.onload = function() { // Works most of the time but not all of the time. //…