Posts by Máttheus Spoo • 1,746 points
60 posts
-
0
votes1
answer697
viewsA: Convert PDF code string to arraybuffer/blob for client download
I managed to solve the problem, as follows: In python file, return the return so: return bytearray(response.content) and, when consuming, instead of using jquery’s fetch or ajax, do it archaically:…
-
0
votes1
answer697
viewsQ: Convert PDF code string to arraybuffer/blob for client download
I’ve been having problems for a while, so I decided to ask here, because I’m already out of options. I’m getting a pdf of an api made in java. I get this pdf from the backend, in python, because I…
-
11
votes3
answers189
viewsQ: Why do we not receive an error when we call an undeclared variable as a window property?
We initially have this: var a = 0; console.log(window.a === a); // true Okay, so here we prove that when we declare a variable in global scope, it becomes a property of the object window. Now, we…
-
1
votes1
answer143
viewsQ: What is the need to declare the constructor/super of an extended class?
I have a class, example: class Animal { constructor(raca) { this._raca = raca; } get raca() { return this._raca; } printRaca = function() { console.log(this._raca); } } And then I extend it this…
-
2
votes1
answer36
viewsQ: Loop that changes the Hue-Rotate
I was playing with a snippet I made just for fun and I came across a problem I can’t find a reason for your cause. Follow the snippet: var i = 0; setInterval(function() {…
-
1
votes3
answers1089
viewsA: Function - show password!
You can do it this way, although there are better ways: $('.input').keyup(function() { if($(this).val().length > 0) { $('#show_key').removeClass('show_key'); } }); $('.input').focusout(function()…
-
1
votes1
answer29
viewsQ: Doubt regarding the extension of the Date object
I’m having a problem whose cause I can’t identify. I have the following builder: class ExtDate extends Date { constructor () { super(); } foo() { console.log('bar'); } } Theoretically it should do…
-
1
votes1
answer49
viewsQ: Clone a native javascript constructor without changing the original
I’m trying to create a personal library, where the original idea was to extend native javascript objects with various useful functions. After reading a little, I ended up convincing myself that…
-
22
votes2
answers153
viewsQ: Why can’t I call methods directly in a Javascript number?
A simple question, but it’s making me curious. I know that in javascript everything is warpado in some object constructor, so I can call string methods even if the string is not an object in theory.…
javascriptasked Máttheus Spoo 1,746 -
0
votes1
answer46
viewsA: Reset button for font size control (accessibility)
Make another array to save the original value, store that value in it next to the first data collection for the fonts array, and then make the same logic. var $btnAumentar = $("#btnAumentar"); var…
-
2
votes2
answers70
viewsA: Create Listener for multiple dynamically generated Checkboxes
If you want to simply add an event to all your checkboxes, you can use the code below: var cbs = document.querySelectorAll('#checkBoxes > input[type="checkbox"]'); cbs.forEach(function(cb) {…
javascriptanswered Máttheus Spoo 1,746 -
1
votes1
answer297
viewsA: Change a date input when changing select
Your code works correctly, the problem is that an input of the date type only receives values in the date format. Change the value of options to dates in the format yyyy-mm-dd and will work normal.…
-
-1
votes3
answers24130
viewsA: HTML button go to link
Just as an alternative, the current answers already do what you want. This does not use javascript, only html and css optionally. <button><a target="_blank"…
-
2
votes1
answer96
viewsA: Old-fashioned logic error in Javascript?
Correcting only what you’ve assembled. function verificar(elemento) { if(elemento.innerHTML == "") { elemento.innerHTML = "X"; } else { elemento.innerHTML = "Y"; } } .container { max-width: 130px; }…
javascriptanswered Máttheus Spoo 1,746 -
1
votes1
answer70
viewsQ: Try-catch in loop causing error
I have the following code, which tries to click a button after 60 seconds, and if it has not pressed, try again after 60 seconds. while(true) { var timeout = setTimeout(function() { try{…
-
0
votes1
answer237
viewsA: Updating date and clock
Okay, follow the code. document.getElementById('relogio').value = document.getElementById('Hoje').value function relogio() { var valor = document.getElementById('relogio').value.split(' '); //divide…
-
5
votes3
answers370
viewsA: How to get the day with two houses in JS
There are better ways to do this. Follow one of them: function getDataMinima(){ var dataMinima = new Date(); dataMinima.setFullYear(dataMinima.getFullYear()-130); console.log("entrou na função…
javascriptanswered Máttheus Spoo 1,746 -
3
votes1
answer830
viewsQ: Difference between // and /*...*/
As far as I knew, use // to comment on a line and /*...*/ was the same thing, with the difference that the second covered more than one line if needed. Is there ANY difference between doing // var a…
-
0
votes0
answers1602
viewsQ: Line break inside string that is inside a string template
I know that to break lines inside string, we use the operator \n. I also know that within template strings, we can do it using only the backslash, this way. var string = `Uma linha \ duas linhas \…
-
26
votes2
answers11240
viewsA: Difference between splice() and Slice()
As much as they look alike or alike, they operate very differently. Splice Operates with 1 or more (undefined parameters). The first parameter is the index from which you should start the deletion,…
-
1
votes0
answers46
viewsQ: Require client-side
Good morning. In the company where I work, there is a kind of require client-side to import npm without it existing on the page. It is used to insert form scripts within the page. The code looks…
-
0
votes1
answer99
viewsA: Javascript set attribute in script tag with variable
It follows a way of doing it, although I don’t know if it’s the ideal way or if it meets what you want to do with it in particular: <script> token = "ablsicn05101dad10561" </script>…
-
3
votes1
answer89
viewsA: "Cut" a variable
You can do this using arrays and the method split. Behold: var exemplo = 'AcloseBcloseCclose'; var variaveis = exemplo.split('close'); console.log(variaveis[0], variaveis[1], variaveis[2])…
-
7
votes5
answers1237
viewsA: What is the difference between substr and substring?
Since you decided for some reason to copy Soen’s question, I will give you the same answer that is in the post. The difference is in the second argument. The second substring argument is the index…
-
2
votes1
answer558
viewsQ: Size of "Maximum call stack"
It’s a question that has more to do with curiosity, to understand how it works. I know that if I call a function within it itself indefinitely I get the error Uncaught RangeError: Maximum call stack…
javascriptasked Máttheus Spoo 1,746 -
0
votes3
answers6987
viewsA: Format DD-MM-YYYY string jquery date
There are some ways to do this, I’ll offer my way that can be a little tricky. $("#dataadmissao").change(function() { var data = new Date($(this).val()); //cria um objeto de data com o valor…
-
5
votes5
answers713
viewsA: indexof does not find element in an array
To find objects within an array, use the findIndex, thus: pessoas = []; pessoas.push({"nome": "Pedro"}) pessoas.push({"nome": "João"}) pessoas.push({"nome": "Maria"}) pessoas.push({"nome": "José"})…
-
5
votes1
answer7037
viewsQ: When to use querySelector instead of getElementById?
I looked for some information on the internet about this already, including in Soen, however I could not reach an exact conclusion. I must point out that the issue is not only about performance, but…
javascriptasked Máttheus Spoo 1,746 -
1
votes1
answer64
viewsA: Bing API Consumption
Try to do console.log(data) and you’ll understand the problem. data is a prop, not an object. Change your code to: var data; const promise =…
-
0
votes1
answer487
viewsA: How to block retroactive dates in input datetime?
Try it this way. Note: Does not validate the hours, only the day. $("#edit-profile").submit(function(e) { var agendamento = $("#agend").val().split('T'); agendamento = new…
-
1
votes2
answers261
viewsA: Remove Button for javascript
Currently it is not possible to disable the button, but a solution could be to force the person to write opening another prompt when the initial is canceled: function noRefuse() { do { x =…
javascriptanswered Máttheus Spoo 1,746 -
1
votes1
answer68
viewsA: Error javascript comparison operators
I think what you want to do here is this: var isOk = /[A-Z][a-zA-Z][^#&<>\"~;$^%{}?]{1,20}$/; var nome = prompt("Digite o nome:"); (function testar(){ if(!nome) { //se não for digitado…
javascriptanswered Máttheus Spoo 1,746 -
0
votes3
answers50
viewsA: Passing array parameters to array
Knowing that arrays and objects are very similar in JS, you can refer to a property of an object using [] and putting the name in, and vice versa. Example: var obj = { prop1 = 1, prop2 = 2 }…
javascriptanswered Máttheus Spoo 1,746 -
2
votes2
answers2676
viewsA: Javascript display date of the day before the current
There’s a much simpler way to do that using setTime(). This command sets the time of the date object of your choice, accepting parameters from -1 to 24. From 0 to 23, he arranges hours correctly,…
javascriptanswered Máttheus Spoo 1,746 -
1
votes2
answers106
viewsA: Background image is not replicated on other pages when using onChange function
Come on. Your problem happens because you replicate several equal Ids within the same page. The function refers to the ID by itself, does not know how to differentiate which of the Ids you want. The…
-
3
votes1
answer88
viewsA: Help with onchange function
Try to do it that way: function myFunction() { var x = document.getElementById("mySelect").value; document.getElementById("demo").innerHTML = x; document.getElementById("imagem").src = "img/gab" + x…
-
3
votes3
answers232
viewsA: Convert Date to date field
Simple as that: var data = '24/10/2018'; var date = data.split('/').reverse().join('-'); console.log(date); Edit.: I realized now that the date only comes with 2 digits of the year, and you need the…
-
0
votes1
answer148
viewsA: Check and display message if the date is less than the Current Date
Well, initially, I noticed that you referenced the form with the variable formulario, but used the onsubmit in a variable form. I don’t know if it was mistake or purpose, but anyway. To get the…
-
7
votes1
answer127
viewsQ: What is the use / reason for the existence of new Object();?
While I was studying a little bit more about objects, I came across things like new String , new Number, etc.. I got curious, and I went to learn. I understood the functioning, despite having my…
-
-1
votes1
answer81
viewsA: After Alert open modal
Leaving the answer here for future consultation cases. The error is in trying to display the modal with it still open. When you call the function the modal has not yet closed, then ends up…
javascriptanswered Máttheus Spoo 1,746 -
1
votes1
answer523
viewsA: Let only mark a dynamic Checkbox table
Translating the answer from here(adapted): + "<td>" + "<input type='checkbox' class='link-check' onchange="cbChange(this)" />" + "</td>" // ... function cbChange(obj) { var cbs =…
-
0
votes1
answer194
viewsQ: Function that returns another function by returning itself
First of all, I’m asking this out of sheer curiosity, there’s no real application where that would be useful (or has it? I don’t know). I know that it is possible to make a function return another…
javascriptasked Máttheus Spoo 1,746 -
1
votes2
answers525
viewsA: jQuery mask is not working
I have a code ready that I use, I will make available: $("#telefone") .mask("(99) 9999-9999?9") .focusout(function () { var phone = this.value.replace(/\D/g, ''); $(this).unmask().mask(phone.length…
-
1
votes2
answers73
viewsQ: jquery selector for a single cell of a "table" made with bootstrap
Simple question, but I can’t find a way to do it. I need to replace a value within one of the "cells" of each row in this table. Follows the code (extensive but simple): <div class="col s12">…
-
-1
votes1
answer1328
viewsA: Create a javascript timer
Try to follow this template and adapt to your code: function contagem() { timer = 600; return function() { var minutos, segundos; minutos = Math.floor(timer/60); segundos = timer%60 <= 9 ? '0' +…
javascriptanswered Máttheus Spoo 1,746 -
0
votes1
answer230
viewsA: How to create dynamic checkbox?
You can do this way using pure JS: HTML: <input type="checkbox" id="id_checkbox"> <p>Digite a data:</p> <input id="id_data" name="data" placeholder="Digite a data do Vencimento"…
-
0
votes2
answers736
viewsA: Change javascript object names
You can’t have them all with the same name. You can do "teste1", "teste2", "teste3", and so on, but calling all the properties of an object with the same name will cause you serious problems. That…
-
0
votes1
answer210
viewsA: Calculate values with Inputy type="range" and Javascript
Try to do it this way: Html: <div id="ranges"> Range <input type="range" class="observe" id="range1"> <input type="range" class="observe" id="range2"> </div> <div>…
-
0
votes3
answers2026
viewsA: How to change the color of the form button with javascript?
Try it this way: Javascript: function verificaCampos() { if(campoSenha.value == campoConfirmarSenha.value && campoSenha.value.length > 8) botao.disabled = false;…
javascriptanswered Máttheus Spoo 1,746 -
4
votes3
answers216
viewsQ: How does date comparison work using . toLocaleDateString();?
It is a doubt that I have some time and I can not find an answer anywhere on the internet (I searched here and on Soen). given the following code: var hoje = new Date(2018, 08,…
javascriptasked Máttheus Spoo 1,746