Posts by Sergio • 133,294 points
2,786 posts
-
3
votes2
answers303
viewsA: Change background by clicking the checkbox
Here is a suggestion. The code is generated from JSON, changes the color when selected and the current state of the selections is saved (and updated) in the variable escolhidas. Suggestion: // var…
javascriptanswered Sergio 133,294 -
4
votes1
answer33
viewsA: Short does not recognize entire date
To organize an array of Date you have to use timestamps and not the text version of a date. It uses the .getTime() and it will already work as you want. You will have to convert this Data and Hora…
-
1
votes1
answer1393
viewsA: res.json Nodejs/ Express
Every time you call taskList.getTaskListById(id) you have to pass the res. But I don’t think you should pass the res so for other functions. It is better to res be called with the result of the…
-
1
votes1
answer452
viewsA: Promise not returning value
When you do data: axios.get(contato.id_url) this var return a file to data, and what you want is the value of that ajax. Then you have to solve that ajax(s) first and then set data. Suggestion:…
-
2
votes1
answer69
viewsA: Javascript - Doubt when manipulating div’s values with variables
You can do it by joining two lines: var valorOrigem = original.nextElementSibling.textContent; div.nextElementSibling.value = Number(div.nextElementSibling.value) + Number(valorOrigem); //Drag'n…
-
8
votes3
answers4625
viewsA: toLocaleString R$ Brazilian
This is configurable with the minimumFractionDigits and maximumFractionDigits. If you want to have the decimal number fixed then give the same number to the two. These values can go from 0 to 20.…
javascriptanswered Sergio 133,294 -
3
votes2
answers435
viewsA: How to appear required in an input without form?
You can use the selector :invalid to apply CSS to the non-validated input. The only drawback is that the CSS loads right from the start. So you can add a class to join the element when you first…
javascriptanswered Sergio 133,294 -
2
votes4
answers1933
viewsA: How to choose a convention for variable and function names?
Although it is very important to have a style defined when we work as a team, it is difficult to implement in old code, and has a very large component of personal taste. That is, they have (and they…
-
1
votes1
answer50
viewsA: Event load inside event load?
Generates an array with these scripts and then uploads it to Javascript like this: <script> const scripts = [ <?php $scripts = dir("js"); while ($script = $scripts->read()) if ($scripts…
-
9
votes5
answers4681
viewsA: How to make a Rigger for a SEM jQuery event?
Generating native events in native Javascript can be a headache. I remember a while ago I made a test to generate event wheel in Mootools and the function to trigger that event was like this:…
-
1
votes1
answer101
viewsA: Pseudo-elements in CSS3 does not appear in browser
CSS does not support nesting style &:before{, this is language syntax that needs to be compiled for CSS like less, sass or stylus. Use it like this: .circular-progress:before { Example:…
-
4
votes1
answer151
viewsA: Linear-gradient does not appear in CSS3
Nowadays it is only possible to use transparency in linear-gradient with rbga. However soon this will be extended to HEX as well, adding a parameter to the following, also hexadecimal, i.e. 0-F.…
-
2
votes1
answer1284
viewsA: Show the number of rows and columns Javascript
Your code was basically correct. I changed some things: taken <div class='coluna_verde'> from within the table’s HTML as it is invalid syntax. I passed the class to the td. removed the…
-
1
votes1
answer191
viewsA: How to delete old files from a specific extension?
You can use the method fs.stat. This method provides an object/class fs.Stats which has information on creation date, last modification date and other file features. To use you have to read all the…
-
2
votes2
answers100
viewsA: Jscript - Finding the id of the previous div
You have many ways, you can go through: .parentElement.parentElement (works but will break if you change the structure of the DOM) using recent technology .closest() (not supported in IE) together…
-
7
votes1
answer58
viewsA: Is it possible to get the value of a div?
You can get the .textContent and then parse to convert to Numero. var text = document.getElementById("valor0").textContent; var numero = Number(text); console.log(typeof text, text, '||', typeof…
-
1
votes1
answer255
viewsA: Hide component outside the router-Viewer
The tools available on the Vue-router are: beforeEach fields meta Configure each route that needs authentication with meta: { requiresAuth: true }. You can put that on children as is in the…
-
6
votes2
answers245
viewsA: Add a month to jQuery
var date = new Date(); console.log(date); // "2017-10-04T20:36:17.560Z" date.setMonth(date.getMonth() + 1); console.log(date); // "2017-11-04T21:36:17.560Z" Uses the .getMonth() to know the date…
-
2
votes1
answer912
viewsA: Creating an array from another array
You must use the .map to map from one object to another. var subselecao = contatos.map(function(contacto) { return { nome: contacto.nome, id: contacto.id }; }); An example would be like this: var…
javascriptanswered Sergio 133,294 -
1
votes2
answers320
viewsA: How to toggle table colors by grouping by a specific table field?
You can create a variable/flag to know if the number has changed and with that change color. Example: $corEmUso = 'white'; $ultimaComanda = null; while($linha=mysql_fetch_array($buscarucomanda)){ if…
-
3
votes2
answers60
viewsA: How to find a caraceter in the string and cut string to it and after it
You can split/explode by this character, and so you have the string separated. Then you use substr to limit the second part to .. $ID = '3803_452.jpg'; $partes = explode('_', $ID); $id = $partes[0];…
-
17
votes4
answers6957
viewsA: What is the difference between i++ and ++i?
There is a slight difference between the two. The i++ ("post-increment") returns the initial value of i and the ++i ("preincrement") returns the incremented value of i. Example: int i = 0; int j =…
-
5
votes2
answers765
viewsA: Help with jQuery. on calculation of plots!
$(document).ready(function() { var total = 600; // valor base do produto $('#valor, #nParcelas').on('change input', function(e) { var valor =…
-
18
votes5
answers19971
viewsA: Validate regular expression name and surname
The problem is that you are using dot, which is for any character except line terminators. Getting it out will already work. . Matches any Character (except for line terminators) function…
-
4
votes1
answer486
viewsA: Grab Object in JSON
What you seek is document.getElementById("test").innerHTML = response.query.results.json.name; If you look at the JSON that the API returns, these are the properties you have to go through. Example:…
-
6
votes1
answer871
viewsA: Is there a difference between window.addeventlistener and addeventlistener?
None, they are the same thing. It is a method of window made available in the global scope. All methods/properties of window are in the global scope and can be accessed via object:…
javascriptanswered Sergio 133,294 -
1
votes2
answers247
viewsA: How to change the color of a div Parent relative to the size of the Childs
Interesting functionality! You could do it like this: const divs = [].slice.call(document.querySelectorAll('body > div')); // máximo de children const max = Math.max.apply(Math.max, divs.map(div…
-
2
votes1
answer1991
viewsA: Remove Timezone on request with Node.js and express.js
I suggest using a library for conversion. For example, the extension of Moment.js to timzones, the Moment-timzone. To do it natively you can use UTC and add the difference to your time, or format…
-
2
votes1
answer68
viewsA: Vuejs/Javascript - components and variables
I suggest you create an object so you can refer keys with these strings. Something like that: import produtos from './produtos' import artigos from './artigos' const componentes = { produtos:…
-
3
votes1
answer73
viewsA: javascript does not create html element and does not add to the page
I think you want to insert the p and not the ptexto right? Anyway your code works, see here: function add() { var texto = document.createTextNode("teste"); var p = document.createElement("p"); var…
-
1
votes4
answers114
viewsA: Ajax does not recognize PHP echo
You can use the .trim() Javascript native and do if(resposta.trim() == '<nome>'){. Thus clears blanks and line breaks before comparison.
-
2
votes1
answer596
viewsA: Browse all properties of a Vuejs object
You have two options: change the object internally create a new object and overwrite the old one In your case it makes no difference because the key values are strings. But if they were other…
-
4
votes3
answers229
viewsA: Function within Jquery what is the execution order?
This is probably because the console that’s inside the while is also within a callback ajax, which is asynchronous. In other words, the code fires the ajax requests to store in the bank, exits the…
-
3
votes1
answer339
viewsA: How to add variables correctly?
You must start these counters with 0 and not with []. There is also a lack of logic to decrease these values if a checkbox is unchecked. If you have a function that runs whenever you need it, this…
javascriptanswered Sergio 133,294 -
2
votes1
answer319
viewsA: Node js problem when picking function value
To use this file you can do so in the file that "requires": const {find} = require('./nome-do-ficheiro-da-pergunta.js'); // não sei de onde vem pesquisa, mas assumo que tu sabes find(pesquisa,…
-
2
votes1
answer19
viewsA: In jQuery, how can I make a selection of an element using "this", inside one I’m already selecting
You can use $("input", this) or $(this).find("input"). Example: $('div').each(function() { $("input", this).val('teste'); // seta o value $(this).find("input").attr('disabled', false); // tira o…
-
1
votes2
answers78
viewsA: Javascript code optimization (Jquery)
As a general rule I would say the less jQuery the better. There’s a interesting question with pros and cons here. But to answer your question, you can do it like this in jQuery: var v = 100;…
-
3
votes1
answer23
viewsA: Question about assigning variables in Ecmascript 5
This reading is only once. You have to re-read the value by calling the window.getComputedStyle each time. Independent of being with var, let and const. What you can do is getter that does the work…
-
5
votes1
answer310
viewsA: Create array with string in php?
There’s a PHP function for this, it’s called parse_str and it works like this: $texto = "forma=3&banco=100&agencia=200&conta=300&cheque=404"; parse_str($texto, $array);…
-
2
votes1
answer34
viewsA: Comparison being repeated gradually in different records
The problem is that you add event headphones to each click with .focus and .focusout and he’s piling up and running around. I suggest you change the logic of the code to something like this:…
-
5
votes1
answer389
viewsA: Vuejs v-select Submit
This select doesn’t seem to have a way to stop the submir event in the DOM. So you have to put a div for example around the component to stop Event. You can do it like this: <div…
-
8
votes3
answers3932
viewsA: How to remove an item from an array without knowing the index, only the value?
In simple arrays you can do: var arr = ['a', 'b', 'c']; arr.splice(arr.indexOf('b'), 1); console.log(arr); In object arrays: You can use the findIndex and then use the .splice or else use the…
javascriptanswered Sergio 133,294 -
2
votes1
answer53
viewsA: Showing result always in the same div
In HTML you cannot have duplicate Ids. Each ID must be unique and only exist in 1 element on the whole page. Other than that, which influences your mistake, you better use the this as a starting…
-
2
votes1
answer63
viewsA: How to store span tag texts in a jquery/javascript array?
You’re using $(divs[i]).find( "span" ) but you’re iterating on quest. Should be $(divs[i]).find( "span" ) and in that case you could use native Javascript with .querySelector() var quest =…
-
2
votes1
answer107
viewsA: How to unlink object elements?
You don’t need to clone the element unless you need multiple equals. You can use var semPai = el.parentElement.removeChild(el); and you get the "in hand" element out of the DOM. var div =…
-
3
votes1
answer103
viewsA: Dynamic slot value
You can use the showModal to store the ID of the product you want to show and then do so: // register modal component Vue.component('modal', { template: '#modal' }) // start app new Vue({ el:…
-
3
votes2
answers446
viewsA: Accents problem in Vue-json-excel
Your problem just seems like a typo. Mute "value": "utf8" for "value": "utf-8" jsFiddle: https://jsfiddle.net/Sergio_fiddle/s8wemmyL/…
-
0
votes1
answer62
viewsA: I can’t show data with Vue js
The vue has a native method called update, so you shouldn’t use a method called your update. Before that ajax comes you have to have a method to render safe. That is when the response is still…
-
4
votes1
answer1584
viewsA: Uncaught Domexception: Failed to execute 'send' on 'Xmlhttprequest': The Object’s state must be OPENED
When you do not initialize a variable it is in the global scope and can be modified by code at different places without leaving a trace. This causes very difficult errors to detect and is…
-
3
votes1
answer461
viewsA: Import Axios in Mixins Vuejs
The mistake you get about the import I believe it is related to your version of Node or the lack of compiler (webpack). Anyway what you want to do is possible, but you have to export something in…