Posts by Sergio • 133,294 points
2,786 posts
-
1
votes1
answer114
viewsA: Bind by SQL Server position using JS Node (MSSQL)
You can use it that way with the mysql (link). The idea is how you show in code, use markers ? in the query and then pass an array with the positions whose value should be used instead of the…
-
1
votes4
answers410
viewsA: JS countdown - How to insert a "zero" in front of numbers smaller than 9?
You can do it more cheaply... Suggestion: function atualizaContador(futuro, mostrador, callback) { var el = document.getElementById(mostrador); var contador = setInterval(function() { var agora =…
-
3
votes3
answers2764
viewsA: How to make the selected menu active with jquery?
You can do this in PHP by adding the class, or do it in JS by checking the location.search and looking for the link that corresponds to you. $('.item-menu').click(function(e) {…
-
2
votes2
answers228
views -
2
votes1
answer73
viewsA: generate json within loop
You can think of "mounting an object" instead of thinking of strings that should be transformed into an object... I think what you’re looking for would be something like this: var obj = {}; for (i =…
-
2
votes1
answer94
viewsA: How to make a filter with a text field
Here is a hint. Important steps are: associates the input to data using v-model uses a property computed to give you the filtered array depending on the input value Example: const champions = [{…
-
4
votes3
answers1489
viewsA: Add jQuery hours in real time
You gotta do more than parseInt for hh:mm have to be transformed into minutes, so the hours part has to be multiplied by 60 minutes, etc. Suggestion: function hmToMins(str) { const [hh, mm] =…
-
1
votes1
answer618
viewsA: By clicking the checkbox disable the button
You cannot have duplicate Ids, HTML syntax only allows 1 unique ID per page. Mute id='servicos' class-oriented class='servicos' or passes the this in HTML like this: onclick='desabilitar(this)'>…
javascriptanswered Sergio 133,294 -
4
votes1
answer97
viewsA: Does removing a DOM element also remove your listening?
Removing from the DOM itself does not remove the event headphones. An example of this is that we can keep a reference to the element: const inicio = new Date(); const test =…
-
1
votes1
answer110
viewsA: Syntax Error. Unexpected token '=' in React
Changes these methods of onNameChange = (e) => { for onNameChange(e) {. For two reasons: arrow functions do not allow .bind to another context. That is: const a = () => console.log(this);…
-
1
votes2
answers83
viewsA: Count options disabled from a select with jquery
You don’t need jQuery for that. You can only do it with Javascript and CSS selector :disabled const nrA = document.querySelectorAll('option:disabled').length; console.log('A', nrA); const nrB =…
-
1
votes1
answer119
viewsA: Javascript array in dates
The most logical place for this content mapping seems to be within adicionaClienteNaTabelaViagem. So you could do something like this: formatarData(str){ return [str.slice(0, 4), str.slice(4, 6),…
-
1
votes1
answer41
viewsA: Set variables to call a function
If you want to call the job stateChanged with "pre-configured datapodes usar o.bind`. So the function is not invoked (which is what is happening now) and you can use this data later.…
-
2
votes2
answers71
viewsA: 'Delay' in the attribution/existence of properties in the Vue instance
In similar cases I usually use arrays, pass the content by props and display the elements in the DOM depending on this array. So everything is sequential, with no possible running conditions.…
-
6
votes3
answers549
viewsA: How to filter through attribute on an object / array
If you want to find 1 element then you should use the .find(): $('.btn').on({ mouseenter: function () { const id = this.id; const el = arr.find(obj => obj.projectId == id); } })…
-
3
votes1
answer136
viewsA: Logic Promisses or callback with Sweetalert and Vuejs
Instead of thinking about if/else asynchronous thinks that the then receives a function if and another else. In other words, this logic is in the code of mixin And what you should do is call other…
-
1
votes2
answers160
viewsA: Dynamic properties in Vue 2
In Vue as you mentioned it forces you to instantiate the empty property in data. One solution is to create a reference to the element created in the template with ref. So in the template you can…
-
2
votes1
answer36
viewsA: Login with AJAX and PHP with database(Why is it wrong?)
You must declare properties of the object data and not declare variables within the object. Mute data:{ var cpf = $('#cpf').val(), var senha = $('#senha').val(); }, for data:{ cpf: $('#cpf').val(),…
-
6
votes2
answers791
viewsA: How does the Sort method work?
The function .sort should always return numbers. Negative, positive or zero. That is, this function is badly drawn. To specification is clear: Returns to Negative value if x < y, zero if x = y,…
javascriptanswered Sergio 133,294 -
1
votes1
answer1168
viewsA: How to pass headers on request with Vue.js 2
Taking a look at Vue-Resource documentation, you can pass headers like this: getFilmes: function () { const token = localStorage.getItem('iflix-user-token'); this.$http.get(Api.url + '/filme',…
-
1
votes2
answers156
viewsA: Algorithm simulation of taximeter
If the night time is between 1 and 7 then you have to isolate that period with &&: hora >= bandeira1 && hora < bandeira2 Suggestion: const taximetro = function( /* N bandeiras…
-
1
votes1
answer97
viewsA: Compare a string array with another string array and create a new array
You can go through this string and cut the beginning by checking if this substring starts with any of the pieces that array2 has. Example: const array1 = ['azxsdfghjkazxfgtfgt']; const array2 =…
-
3
votes1
answer434
viewsA: When can the setSelectionRange method of Htmlinputelement be used?
I believe this happens because it is only possible to select content in elements that are in focus. Although I did not find this written, it makes sense and in the example of MDN is what they do.…
-
3
votes2
answers2359
viewsA: Avoid form Ubmit by pressing the Enter key
You have many ways. One of them is to use @keydown.enter.prevent in <form>. This prevents Submit but also prevents enter to be used where it was pressed, and perhaps this effect is unwanted.…
-
6
votes1
answer98
viewsA: Git, Doubt when I commit
Create a branch/branch where you have this new/Feature feature. When it is ready merge with the master. git checkout master # criar novo ramo a partir do master git checkout -b nova-ideia And then…
-
1
votes1
answer761
viewsA: Vuejs: how to check all checks and count your quantity?
Use one more array multipleChecks to keep the marked owner Ids. Use @click="toggle($event, lista[i].lojas)" to be able to call a method with the stores of a given owner and be able to insert/remove…
-
1
votes2
answers40
viewsA: Javascript - Function that changes the background of the parent element
Pass the event to that function and then do e.target.closest('td') to find the td. Example: function teste(e) { var el = e.target.closest('td'); el.style.backgroundColor = '#FF0000'; }…
-
4
votes1
answer13414
viewsA: Error: "Can’t set headers after they are sent" on Node.js / Express
Recalling another question I saw that the code of is: function setUserByParams(req, res) { return con.query(` INSERT INTO db_lifeapp.tb_user ( des_name, des_email, des_endereco, num_cep, num_phone,…
-
2
votes2
answers73
viewsA: Form Validation with Javascript
In this case it avoids giving return on each of the if. You can start the "optimistic" function with var valid = true; and then switch to false if one of them fails. Example: function validate() {…
-
0
votes4
answers635
viewsA: I want to subtract elements from an array in JS, but that returns several results
You can do it like this: var arrayExemplo = [2, 5, 9, 10, 15]; function subtrair(arr) { return arr.reduceRight((res, el, i, arr) => { return (i == 0) ? res : res.concat(el - arr[i - 1]); },…
javascriptanswered Sergio 133,294 -
4
votes1
answer263
viewsA: Picking up more than one element with Jquery/Javascript
You can use the comma to concatenate selectors into CSS. You were close, it would be like this: $j('.filters__list, .filters__filtered').slideToggle(50); If you have many classes to join maybe it is…
-
4
votes3
answers70
viewsA: Applying Hover to an article
The reason this doesn’t work is because styles applied inline in HTML have more weight than styles in CSS. Take a look at this question about this in detail here. article.item { margin: 5px; border:…
-
1
votes1
answer1282
viewsA: Filter an html table with a button
It would be better to give a data-estado each column. Then use the same value as the data-estado in the button id. Example: var tds = document.querySelectorAll('table td[data-estado]');…
-
0
votes2
answers83
viewsA: Swap Button for Auto Sum
Here is a suggestion, sending the value entered directly into onkeyuphere: <input name="campo1" id="demo4" onkeyup="soma(Number(this.value))"> var resultado =…
javascriptanswered Sergio 133,294 -
2
votes2
answers436
viewsA: Click action with jquery does not work with duplicate items
Ids must be unique. That means you can only have 1 per page. In these cases you should use classes to group elements with the same identifier. Mute: #deletar for .deletar on the jQuery selector…
-
1
votes1
answer183
viewsA: Xmlhttprequest Good example applied
You need to break it down into steps to get control of progress. An example would be like this, using Promises: function ajax(nome) { return new Promise(function(resolve, reject) { var url =…
javascriptanswered Sergio 133,294 -
0
votes3
answers25
viewsA: Help with uncheck
You can use $(this).toggleClass('checked'); to place or remove the class as a switch. Example: $('.rating-star').click(function() { $(this).siblings().removeClass('checked');…
-
2
votes1
answer333
viewsA: How to perform . filter between arrays/objects Angularjs Javascript
What you need is, for example: const filtrados = $scope.listademercadoria1.filter( obj => $scope.listaDoCarrinho.find(item => obj.id == item.id) ); So you search every listademercadoria1 if…
-
1
votes1
answer1145
viewsA: Express return post
You have to create asynchronous logic in that middleware to wait for the comic’s answer before calling the next. You can do it like this: router.post('/user', (req, res, next) => { var obj = {…
-
1
votes2
answers270
viewsA: JAVASCRIPT concatenate
If deleting is text, then you don’t need quotes and you can do so: html += '<a onclick=excluirCD(' + rows[i].id_cd + ')>excluir</a>';
javascriptanswered Sergio 133,294 -
1
votes1
answer63
viewsA: Calling Function
To use the .search you have to pass a Regexp. In your example you’re passing a String. Since your input is a string, then you can use the .includes() or the indexOf. So I could stay: function…
javascriptanswered Sergio 133,294 -
0
votes2
answers22
viewsA: How to update a service collection by calling index a second service?
I think you need to rewrite .data_collection to trigger Angular’s reactivity. Do a mapping where you add the extra information and then replenish everything and let Angular detect what needs to be…
-
1
votes2
answers272
viewsA: Problem using append js element does not appear
I suggest instead of changing the whole picture, change only the src and use the load to start the next fadein only after the image is loaded. Thus: $('#lp-pom-image-1674').on('click', function(e) {…
-
4
votes3
answers556
viewsA: Change class after 3s via javascript
The syntax for this would be like this: setTimeout(function(){ document.querySelector('.oculto').classList.add('visivel'); }, 3 * 1000); As Javascript works in milliseconds you have to pass 3000 ms…
-
5
votes1
answer408
viewsA: How to prevent the child element from activating the parent element event?
In this case it is best to compare whether the event.target is the same as the element that has the headphone of the event, ie the this. $("optgroup").on("click", function(e) { if (e.target != this)…
-
1
votes1
answer131
viewsA: How to row and row with separate rows in Javascript?
function FIFO(max) { this.comprimentoFilas = max || 3; this.filas = []; this.adicionar = function(arr) { if (!arr) { arr = []; for (var i = 0; i < this.comprimentoFilas; i++) {…
-
1
votes1
answer148
viewsA: Javascript does not recognize Json
The JSON you receive from the server is an object: { "api": "api", "List": [{ and the .forEach works on arrays. So you have to pass the .List directly because the .List is an array. var obj =…
javascriptanswered Sergio 133,294 -
3
votes1
answer47
viewsA: Input the fadeout sound when you click the pause button
You have to use the .volume within a cycle of small adjustments to simulate the effect fadeout|fadein. An example could be joining the play|pause also, so: const fade = (function(){ let fading =…
-
1
votes1
answer45
viewsA: How to add a new position to the object based on other fields
You can use a method to do that too. In the template you would have: <div v-for="obj in dados">{{percentagem(obj)}}</div> and in the methods: methods: { percentagem(obj) { const inicio =…
-
4
votes3
answers641
viewsA: Check if window load is false
I usually make it simple without jQuery like this: function domReady(cb) { (function checkDomReady() { var state = document.readyState; if (state == 'loaded' || state == 'complete') cb(); else…