Posts by Sam • 79,597 points
3,121 posts
-
1
votes1
answer84
viewsA: Open Material Box when dragging to next image
Enter this code on the page: $(document).on("mousedown", ".materialboxed.active, #materialbox-overlay", function(){ setTimeout(function(){ if($(".materialboxed.active").length){ var instance =…
-
0
votes1
answer40
viewsA: I have a field in which when activating checkebox, it disables the input
Can use a localStorage to save the value of the parameter selecionado. Then you check if it exists and is equal to "true" and trigger a click on the checkbox. But put a id at the checkbox to know…
-
0
votes1
answer90
viewsA: Is there any difference or advantage of using drag and drop events and mouse events?
There is a lot of difference, because in your second example (using mouse events) it does not work. You are creating a false effect drag-and-drop. See: when you click on the div "drag" you trigger…
javascriptanswered Sam 79,597 -
1
votes1
answer1928
viewsA: Javascript - Uncaught Referenceerror: {funcao} is not defined
When you load a chunk of script via AJAX, it is included in the DOM but is not loaded into the JS memory, so the code is not executed and the functions do not exist. What you can do is check if the…
-
2
votes1
answer50
viewsA: Avoid many requests in Select
Disable the select that triggers the event change while AJAX is processed and enabled again after AJAX processing. This prevents bottleneck of processing if the user keeps changing the option…
-
3
votes3
answers5507
viewsA: Count how many elements are duplicated in a string
After adjusting the order of the characters with .split() + .sort() + .join() could make a while that will rotate from 0 up to the size of the string, picking up distinct characters. Inside the…
-
4
votes1
answer331
viewsQ: What does the "$" dollar mean in the browser console or in Javascript?
On any empty page (no library at all), when typing a $ in the browser console is returned a function, as shown in the output below: ƒ $(selector, [startNode]) { [Command Line API] } If I type two $…
-
1
votes2
answers326
viewsA: Get radio input value display on same page, no refresh
First thing is that you should not repeat the same id in more than one element. A id should be unique. See that you put the id="frete" on both radios. Remove these id’s because it is not even…
-
2
votes3
answers213
viewsA: Why does the DIV break line when resizing?
If the div has a minimum width of 450px, when the largura da tela divida por 3 is less than 450px (disregarding the padding that you put in the header), the middle div will continue with the same…
-
2
votes3
answers717
viewsA: Ternary operator with three possible conditions
I could wear a suit like that: status é diferente de 0? (true) ↓ status ? status < 2 ? 'icon1' : 'icon2' : 'icon0' \___________________________/ ↓ | se status for este bloco é caso status igual a…
javascriptanswered Sam 79,597 -
2
votes2
answers609
viewsA: Regex for full sentence in capital letters
The @hkotsubo response is very good and covers any type of situation if there is a possibility that the text contains accented letters that are not part of Portuguese (e.g.: ¡, ö, ă etc.). But I…
-
1
votes2
answers75
viewsA: I would like to know how to change the color of a button for 1 second and then return the original color automatically
For this just empty the property background-color. You can do this by adding a condition if before the if terminating the function: if(i1 > 1){ document.getElementById(i1-1).style.backgroundColor…
-
4
votes1
answer324
viewsA: How to insert single quotes inside simple html quotes
Use the escape character ' referring to single quotation marks ': <input type='text' class='form-control' name='patientsName' id='patientsName' placeholder='Patient's Name'>…
-
0
votes2
answers89
viewsA: Change string characters, except the last 4
Can use .padStart(), which dispenses with the use of the loop for: function criptografar(dados){ if(dados.length > 4) return dados.slice(-4).padStart(dados.length, "#"); return dados; }…
-
1
votes2
answers185
viewsA: Why pass Event in a function as a parameter?
Modern browsers (the current ones, including the infamous IE11) have incorporated the event as native property of the object window. If you open the console and run event will return undefined, that…
javascriptanswered Sam 79,597 -
0
votes1
answer70
viewsA: Problem running external script
How your script is in <head>, it will run before the browser builds the body, and you’re trying to access the body that does not yet exist in the DOM, resulting in error: Cannot read Property…
-
2
votes1
answer36
viewsA: How to set the scrolling time of the page by clicking on the menu link and it redirects to a specific section? (with pure js)
Set the time maybe using some function with setInterval or setTimeout, but you can set a smooth scroll with a speed using this function: function scrollSuave(old, des, atu){ var easing = function…
javascriptanswered Sam 79,597 -
4
votes2
answers462
viewsA: How to recover an array saved on localStorage
I don’t know if it was a typo here, but the object window that’s all lower case (you capitalized the "W", which will result in error). You don’t need to use JSON parse, just put it on localStorage…
-
3
votes1
answer245
viewsA: How do I resolve the problem Uncaught Typeerror: Cannot read Property 'Cells' of Undefined in this context?
It turns out that you are trying to access a non-existent element in the table, either a column or a row. For example, if you try to access the property .cells of a .rows will return the error…
-
2
votes1
answer45
views -
1
votes2
answers769
viewsA: How to return values with numbers in an array
You are trying to access an array value that does not exist (index [4]) in making i <= 4. With this is returning undefined, and trying to add undefined with some value will result in NaN. Change…
-
1
votes1
answer289
viewsA: Show/Hide "a div" by clicking on radio button
Just use the id radio as selector. But radio behaves differently than checkbox, which can be checked/unchecked. #termos:checked ~ #termoTexto{ display: block; } #termoTexto { display:none; }…
-
1
votes1
answer93
viewsA: Clone element by changing name value
One solution is to create array patterns by separating them by the view codes. For example, let’s say I cloned the fields this way: The result will be: Array ( [fx] => Array ( [a] =>…
-
3
votes4
answers2171
viewsA: CSS, Bootstrap4 Cards Side by Side
Include cards in a div .container-fluid and add other native Bootstrap 4 classes to convert to flexbox: <div class="container-fluid d-flex flex-wrap"> COLOQUE OS CARDS AQUI </div> How…
-
2
votes2
answers45
viewsA: Let div with height auto and with the bottom set
One solution is to use the function calc() in the max-height (then you don’t need the bottom and of height). Just subtract the 100vh (height of the viewport) by 20px (distance from the top + desired…
-
4
votes2
answers608
viewsA: Take the smallest value of an object array
With .reduce() you find the object with the lowest value in the key currentTasks: const obj = { "programmers": [ { "id": 1, "name": "Eduardo Candido", "currentTasks": 1 }, { "id":2, "name": "João…
-
4
votes1
answer298
viewsA: How to make low relief effect in texts?
Searching in Google I found a Codepen that makes a similar effect that was pleased: .box{ font-family: Arial; background: #f5f5f5; font-size: 4em; font-weight: bold; padding: 20px; } .box span{…
-
0
votes1
answer298
viewsQ: How to make low relief effect in texts?
I would like to make a bas-relief effect on a text. Using the property text-shadow it is possible to do this, as shown below: .box{ font-family: Arial; background: #bababa; text-shadow: 1px 1px 1px…
-
1
votes1
answer32
viewsA: Add d-block to inputs automatically
First thing is forget id’s. Since an id should be unique on the page, there is no way to handle multiple elements with the same id, as you are doing in the line function: var element =…
-
0
votes2
answers96
viewsA: Radio input array in PHP form
Just use the name's in array form concatenating the variable $n of the loop as contents: name="codresp['.$n.']" So you will have separate collections of name's for each response group: <label…
-
0
votes1
answer276
viewsA: How do I download the contents of a div?
There is a syntax error on this line: var elementHtml = ... + document.getElementById('#teste'); ↑ Should not include hash, only id name: var elementHtml = ... + document.getElementById('teste');…
-
2
votes1
answer34
viewsA: My setInterval function is not working as intended
In addition to not having declared the variables sec and min, function call on the setInterval is wrong: setInterval(conta_seg(), 1000); ↑↑ When you set the parentheses, you are running the function…
-
2
votes1
answer152
viewsA: How to fix the input text cursor in the middle
The problem there is that you put one padding huge right/left of 314px in the input: padding: 12px 314px; It seems to me to have been a ploy just for the input to be the same width as the div where…
-
3
votes2
answers116
viewsA: How to take all the <td> textContent of a table and assign it to an array?
If you want only the column texts of the clicked row to be included in the array, you must declare the empty array within the event click. Since the tr are the elements that trigger the event click,…
javascriptanswered Sam 79,597 -
1
votes2
answers168
viewsA: Delete/Destroy html table via javascript
The method .empty() jQuery removes all elements from within of a single element (Child nodes), but keeps the element itself in the GIFT. A similar way in pure Javascript, would be to empty the…
-
1
votes1
answer325
viewsA: Remove space from a php string
Do two Places, where the first one removes the \r (carriage return, which is what is generating the extra space), and another replacing the line break \n for ','. Example: $resultado =…
-
1
votes1
answer62
viewsA: Function Sort() makes attribute data="" Undefined
The .data() is a jQuery property assigned to the element. When doing .sort() and then insert the result with .html() for the second time, this property is empty. Instead of using .html(), use…
-
1
votes1
answer32
viewsA: Disappear with an active list when you click on another
Just remove the class .active of all the .control-monteseupc, except what was clicked. For this you use the .not(this): $('.control-monteseupc').click(function () { $('.control-monteseupc')…
-
2
votes2
answers42
viewsA: Retrieve specific information in string
Can use preg_match_all with a regular expression to pick up anything between double quotes of id="": preg_match_all('/id="(.+?)"/', $str, $matches); The expression /id="(.+?)"/ will fetch everything…
-
1
votes1
answer66
viewsA: How do I get a type range to be filled out according to marking?
Use Javascript to apply a background linear-gradient with the percentage proportional to the range value. On the line: this.style.background = 'linear-gradient(to right, yellow 0%, yellow '+ perc…
-
2
votes1
answer104
viewsA: Dynamic textarea when editing form
The problem is that elements dynamically added to the DOM are not listened to by events already created. You will have to use the delegated form of events through the object document: $(document)…
-
2
votes1
answer1311
viewsA: How to show/hide a sidebar based on screen size and push a button?
Failed to add class .collapse on the menu div: <div id="menulinks" class="nav nav-pills collapse"> And you don’t have to put display: none in the CSS in this div, as the control of this is in…
-
2
votes4
answers727
viewsA: Check Object inside an Array using index()
Another way would be to convert the array to string with JSON.stringify() and checking with .indexOf() if you have the object in string form: var numberObjects = [ {number: 1}, {number: 2}, {number:…
javascriptanswered Sam 79,597 -
1
votes2
answers141
viewsA: How to remove elements from a javascript list
If you have a list: <ul id="lista"> <li></li> <li></li> <li></li> </ul> To remove items from the list (all <li>) no need to make loop using…
-
2
votes2
answers51
viewsA: How to return the size of a variable result?
The variable const total is serving only to temporarily store the value of each array position to be compared to the value 8, therefore this variable is not storing all values that are greater than…
javascriptanswered Sam 79,597 -
2
votes2
answers49
viewsA: Show hidden text when switching lines
Change the property text-indent: 3.25em; for padding-left: 3.25em; on the label. The text-indent will only indent the first line of the text, ie if there is line break, the second line in front of…
-
1
votes1
answer82
viewsA: Quill editor formatting button event problem
The problem is that by clicking on one of the formatting buttons of the editor text (bold, italic or underlined) the selected text slightly loses focus and selection, causing the action of the…
-
0
votes2
answers34
viewsA: Jquery by selecting three forms at once
The problem was what was said. The selector $("form") selects all forms from the page at once. Placing a id in each you will differentiate from each other, however nay it is necessary to necessarily…
-
1
votes1
answer226
viewsA: How to make a single request with ajax and jquery?
I guess you already know that one id should be unique on the page so much that it is using a id for each checkbox. So far so good. But using multiple id’s in the same collection of elements is not…
-
0
votes1
answer30
viewsA: Email verification works, but then doesn’t "update" when I type and email correctly
Could put a else in checking the email in PHP by returning a value in the key email, as an "ok", for example: if(mysqli_num_rows($sql)>0) { echo json_encode(array('email' => 'Email já…