Posts by bfavaretto • 64,705 points
902 posts
-
3
votes3
answers1355
viewsA: Simple sum returning Nan
If the result is NaN, one of the terms of the addition is NaN, for all mathematical operations involving NaN yield results NaN. Like parseInt('') also gives NaN, I’d say you’re leaving at least one…
javascriptanswered bfavaretto 64,705 -
9
votes1
answer461
viewsA: In java, a Void that sums, returns value?
void soma (int a, int b) { int s = a + b; System.out.println (s); } That up there is a method, which is a kind of function or subroutine. The first line says that The type of return is void, i.e.,…
-
2
votes3
answers1263
viewsA: How to trigger an event when the value of a variable changes?
Like Victor said in his answer: Your real problem is that "multiple functions can change the value of this variable at any time". That’s the real problem you have to solve. One of the ways to solve…
javascriptanswered bfavaretto 64,705 -
0
votes2
answers55
viewsA: Call class="button" instead of id="download"
Change in the first line: var downloadButton = document.querySelector(".button"); If there is only one element with this class, everything will be fine. But if there is more than one, everything…
javascriptanswered bfavaretto 64,705 -
12
votes3
answers353
viewsA: Is it possible to prevent one of the attributes of an object from being serialized in Javascript?
Another way is to create a nonenumerable property. Nonenumerable properties are not accessed in links for..in, nor are included in JSON generation. Example: var o = {}; Object.defineProperty(o,…
-
5
votes2
answers100
viewsA: Why are you returning Nan?
Yes, the problem is in the draw function. You are trying to multiply the function itself Math.random, and not the return value of it. The correct would be: var sorteia = function(x){ var n =…
javascriptanswered bfavaretto 64,705 -
3
votes3
answers206
viewsA: Countdown - include month
That code already does just about that. It needs to change very little: var months = Math.floor(distance / (1000 * 60 * 60 * 24 * 30)); // veja o * 30 var days = Math.floor(distance / (1000 * 60 *…
javascriptanswered bfavaretto 64,705 -
3
votes2
answers83
viewsA: First item returns Undefined
The value of teste is undefined initially, and when you concatenate with teste+= ..., that undefined is converted to string and concatenated with textoSplit[i]. To resolve, initialize teste as empty…
-
3
votes1
answer309
viewsA: Vuejs: How to access data from a v-for within a method?
You need to pass the car: <a href="#" v-on:click="verificaDetalhe(carro)">Detalhe</a> And get on the other end: methods: { verificaDetalhe: function(carro){ console.log(carro.detalhe);…
vue.jsanswered bfavaretto 64,705 -
2
votes2
answers165
viewsA: How to access the version of a.exe file with PHP?
WARNING: All codes in this answer were written by third parties and have not been tested by me. Beware of using them. No Stack Overflow in English has a similar question, and user Toni posted there…
phpanswered bfavaretto 64,705 -
6
votes4
answers151
viewsA: How to build a class correctly with access methods?
I don’t see much point in creating getters and setters in PHP in many cases. Of course it will depend a lot on the context, how the class was designed and what use you intend to make of its…
-
25
votes4
answers1016
viewsA: Is the use of "private" in C# classes optional?
I do not know if it is clear to you what this modifier does. I recommend reading What is the difference between public, default, protected and private modifiers?, that you have indicated in the…
-
24
votes4
answers453
viewsQ: Table change constraint with subquery
To documentation mysql says: you cannot Modify a table and select from the same table in a subquery you cannot change a table by selecting data from it in a subquery This applies to DELETE, UPDATE…
-
3
votes3
answers1017
viewsA: Is there a limit or restriction on variable name sizes?
The specification does not determine a limit, then the final decision is in charge of each language implementation. Of course there must be limits, because computers are limited in terms of memory…
javascriptanswered bfavaretto 64,705 -
3
votes2
answers77
viewsA: How to get the instance itself (this) in a callback?
There are 4 ways to do this. 1. Save a variable reference The first is that of isac response, and consists of keeping a reference to the object this desired in a variable to which the function has…
-
0
votes2
answers636
viewsA: Wait for ajax response before moving to the loop
I think that my answer is more a curiosity than useful in practice, due to compatibility problems (it won’t work in IE or old browsers). function ajaxPromise(indice) { return new Promise(resolve…
-
1
votes2
answers674
viewsA: Vuejs: how to create a condition for a v-model?
Your Watcher works, but I find it more appropriate to transform chkPosNet in a computed property: var app = new Vue({ el: '#app', data: { slcModalidad: 0 }, computed: { chkPosNet: function() {…
vue.jsanswered bfavaretto 64,705 -
3
votes1
answer972
viewsA: Line breaking in PHP with CSV
Looking quickly, I think this would suffice: echo "<td>" . str_replace("!", "<br>", htmlspecialchars($cell)) . "</td>\n";
-
6
votes5
answers2275
viewsA: How to reduce the search time in a table with more than 200,000 records?
So the result of EXPLAIN shows that the query returns 60k+ rows of the enterprise table. With all those Joins, each of these lines will be combined with each row obtained from the other tables.…
-
8
votes1
answer1588
viewsA: How to obtain value [[Promisevalue]]?
Its variable is a Promise, that is, a promise that a certain value (the one you want to pick up) may be available in the future. When you are, that is, when the promise is settled, it executes the…
javascriptanswered bfavaretto 64,705 -
7
votes2
answers1055
viewsA: What are slots and how do they work and "scoped slots" in Vue.js?
How does the <slot></slot> and scoped slots to receive offspring from another component and pass props to the descending elements? When a component has a slot(s), it is possible to…
-
5
votes1
answer51
viewsA: Ajax without sending the action
Because of how you are calling the function, need one more return outside: ... onsubmit="return alterProduct(this)" ...
-
4
votes1
answer2649
viewsA: Doing a Get using Axios (Vue.js)
The problem is that this in the context of this callback function is no longer your Vue instance. You can use a Arrow Function: .then( res => { console.log(res); console.log(res.data.results);…
-
5
votes3
answers1206
viewsA: Statement "Return" does not work within foreach. Why?
If you want to find a specific item and touch it, you have more appropriate methods, such as find: var item = $scope.items.find(function(item) { return item.codigo == $('#codigo').val(); });…
javascriptanswered bfavaretto 64,705 -
6
votes1
answer44
viewsA: Delete only one phrase from a file using php
$caminho = 'caminho/do/arquivo.txt'; $conteudo = file_get_contents($caminho); file_put_contents($caminho, str_replace('trocar isto', 'por isto', $conteudo));
phpanswered bfavaretto 64,705 -
1
votes2
answers129
viewsA: Image loading inside for loop
If I understand correctly, your bow tie for has to stay out of everything: for(var y = 0; y < VARimg_categoria.length; y++) { var image = new Image(); image.src = VARimg_categoria[y];…
-
0
votes2
answers323
viewsA: Print div with appendchild
I can’t quite understand your restrictions. You need to pass a pro DOM node appendChild, no use passing text. This works, I do not know if it meets you: var div = document.createElement('div');…
javascriptanswered bfavaretto 64,705 -
2
votes1
answer474
viewsA: Can you tell the response time of an AJAX request with jQuery?
You need to save a timestamp from the time of the request, get another at the time of the reply, and compare the two: var inicio = performance.now(); $.get('https://httpbin.org/get').done(…
-
1
votes1
answer22
viewsA: Problem with system loading using "fopen"
The problem is in the function that does the reading. It will read the file until the size returned by filesize("teste.txt"). That function filesize is one of PHP’s cache to try to be faster, and so…
-
2
votes1
answer53
viewsA: deleteRow Do not delete table row completely
You are not calling the function. This: document.getElementById(item).deleteRow should be: document.getElementById(item).deleteRow(0); or simply: x.deleteRow(0); I’m passing zero, which represents…
-
1
votes1
answer185
viewsA: Setting of Div Parent CSS
This is because the internal Ivs are floated. Floated elements do not influence the dimensions of the ancestors. The solution is simple, just put overflow: hidden in #fotos-listagem (a trick to…
cssanswered bfavaretto 64,705 -
8
votes2
answers9256
viewsA: Check if value exists in object array
You came close, only the mapis not the most appropriate method, because it was made to transform one array into another. To delete you will need the index of the element that will be removed, so it…
-
5
votes1
answer346
viewsA: preventDefault does not work
The preventDefault does not work when Event Listener is set inline in HTML (onsubmit="..."). Use addEventListener: document.getElementById('form_id').addEventListener('submit', valida_form, false);…
javascriptanswered bfavaretto 64,705 -
3
votes1
answer74
viewsA: Attribute not defined in a Vue object
Here: titulo_atual: titulo[this.pagina] The this in that context is not the object of type Vue that is being created, and yes the this external (which depends on the context, probably is window).…
-
16
votes5
answers1059
viewsA: Is it possible to convert a 16-bit number to a single byte?
You seem to be missing the conceptual basis for how values are encoded in binary. If each binary digit can only be zero or one, a binary digit can only encode two values. Similarly, two digits allow…
-
2
votes1
answer132
viewsA: callback in function removeClass jQuery
That callback?! This method does not accept callback! Since there are no asynchronous operations involved, simply chain the calls, so: $(".context_menu_pai").removeClass('open').removeAttr("style");…
-
3
votes1
answer35
viewsA: Function to change Height with errors
bannerHolder.css.height == windowSize + 'px'; should be bannerHolder.style.height = windowSize + 'px';
-
1
votes3
answers1664
viewsA: How to use a Global variable in two Jquery codes to perform conditions?
In Javascript each function determines a new scope of variables. And declared functions within other functions view external variables - unless they redeclare variables with the same name locally.…
-
0
votes1
answer45
viewsA: Error in mysql Syntax
Failed to pass the name of the database at the time of connection: mysqli_connect("localhost", "seu_user", "sua_senha", "nome_do_banco");…
-
3
votes3
answers1333
viewsA: How to overwrite a method via prototype on a javascript object?
I think I understand what is confusing you. The operations you do, in short, are: Establishes class inheritance base for class dia (note: it is convention to use uppercase initials for class names…
javascriptanswered bfavaretto 64,705 -
0
votes1
answer2683
viewsA: How to factor n! or ! n?
You’re making it too complicated: x = 5 total = 1 for n in range(x): total = total * (n + 1) print(total)
-
2
votes2
answers71
viewsA: Objects em javascript
I think you want something like that, no arrays, just objects: var clients = {}; clients[client.id] = { 'nome': 'osvaldo', 'sala': 'B1' }; // repetir bloco para demais clientes Testing: var dados =…
-
6
votes1
answer61
viewsA: Body or entity setting standards for web development
Yes, there is the W3C (not to be confused with w3schools for the love of God). It is he who defines the patterns of HTML and CSS. In the case of Javascript, who sets the standards is a committee…
nomenclatureanswered bfavaretto 64,705 -
2
votes1
answer98
viewsA: Ajax request parameter being a variable
When you create a literal object like {tipo: text}, the keys never are variable. Therefore your key is "type" itself, and this is being passed to the server. The only way to use a variable as a key…
jqueryanswered bfavaretto 64,705 -
5
votes1
answer196
viewsA: Access variable from within function: scope problem?
It is not scope problem. The problem is that the function is asynchronous, it is a callback. Then you assign response to dados, but only after the console.log has already spun. Whatever you need to…
javascriptanswered bfavaretto 64,705 -
1
votes3
answers33
viewsA: Print at the top of the page
If understood correctly, you need to make the function return a value and give echo out of it. function resultado ($nota) { return "Sua nota foi tal: ".$nota; } echo resultado(0); // imprime : 'Sua…
phpanswered bfavaretto 64,705 -
4
votes1
answer56
viewsA: Content with code points (Entity) or Unicode characters
w3schools seems to have invented this name "css entities", inspired by html entities. That’s a list of code points Unicode, which can be used "escapes" with \. But you can also use the character…
-
10
votes3
answers1312
viewsA: How to create PHP executable program?
PHP is an interpreted, not compiled language. Its purpose is not to generate desktop applications, but to pre-process HTML. It is even possible to build a desktop application with PHP (see examples…
-
5
votes3
answers1691
viewsA: Why does Javascript return Infinity instead of error when dividing by 0?
I would like to add some information that is not included in the @Sergio replies (which gave a great example of using the Infinity), and @Leocaracciolo (who explained how division by zero tends to…
-
2
votes1
answer693
viewsA: Countdown of days to a future event
Your mistake is on this line: $dia_hora_evento = strtotime(date($timestamp)); You already have the schedule of the event, it is itself $timestamp. You don’t have to do anything on top of it. Just…