Posts by bfavaretto • 64,705 points
902 posts
-
3
votes2
answers746
viewsA: Browse List in Jquery (JSON)
I don’t know what you’ve tried, but it’s very simple: $.getJSON(url_do_seu_json, function(dados) { var volumes = dados.detalhes.listVolumes; volumes.forEach(function(item) { // pegue aqui os dados…
-
19
votes4
answers6072
viewsA: How to write code as an example, without running?
You need to escape the characters that make your tags interpreted as HTML, the < and the >. For example, instead of: <div>Teste</div> use:…
-
9
votes3
answers15590
viewsA: How to call a JS variable for an H1 HTML
Or you fill in the <h1> whole, like this: var count = 0; $("li").each(function(){ count++; }); $('h1').html("I have " + count + " list items"); Or create a span inside to keep only the count:…
-
5
votes4
answers941
viewsA: Time Sync() PHP and Javascript
It looks like you’re getting trouble where you don’t have it. According to the documentation, the function time of PHP: Returns the current time measured in the number of seconds since the Unix Era…
-
3
votes2
answers1173
viewsA: File request . txt via AJAX
You need to use the webserver on both ends. The code is OK, but the screenshot shows that the ajax.html is being accessed in the browser with file:///. You need to access it with HTTP as well.…
-
9
votes3
answers23304
viewsA: What is the difference between "passing by value" and "passing by reference"?
"In the passage by value the argument is copied." OK, but what exactly is copied? The whole object, including all its references? What is copied is exactly the value that was passed as argument.…
-
3
votes2
answers123
viewsA: Convert array to string again
You can use one first split to transform the list into an array, and then an map to generate a new array by transforming each string within it into a number: function bytesFromWords (string) { var…
javascriptanswered bfavaretto 64,705 -
1
votes2
answers798
viewsA: How to determine the value of X using Javascript
As already said the hugomg, is a second-degree equation, and they all have the following form: Ax2 + bx + c = 0 In your case: a = 1056261433 b = 431977909 c = -281860832 - 2.022 = -281860834.022…
javascriptanswered bfavaretto 64,705 -
3
votes4
answers2771
viewsA: How to change the color of a div before loading the page through a script?
If the goal is to change the color of a particular div, the first moment it can be done is so that the div will exist on the page. For example: <!-- esta é a sua div: --> <div…
-
9
votes1
answer8470
viewsA: What is Curl/curl_setopt
The Curl is a tool to create requests on various protocols (including HTTP, HTTPS and FTP, among many others) and get remote content. It exists as a command line tool, and also as a library, the…
-
11
votes3
answers4722
viewsA: How to create a box with lines on both sides with CSS only
It’s actually not that obvious. Almost everything in CSS is box-based, and what you need is a box and two lines. There are several ways to achieve this, and I’ll show you a path using 2 elements: a…
-
0
votes1
answer88
viewsA: Cronjob does not recognize the Codeiginiter controller
The error seems to be in the way you call the script from the command line. According to the manual, you need to navigate to the project folder and run the index.php, passing to it controller and…
-
4
votes1
answer478
viewsA: Add characters before each number
Just break the content into lines and add '55' at the beginning of each. So, for example: var campo = document.querySelector('textarea'); var linhas = campo.value.split("\n"); var novo =…
-
7
votes2
answers70
viewsA: Problem with a Javascript function
The problem is that hasClass, addClass and removeClass expect the class name, not a selector. Therefore, it is not to put the point at the beginning. Other than that, the ifThe ones that check if…
-
4
votes1
answer205
viewsA: Change SVG object color with animation
The element animateColor that you used was discontinued because it is redundant with the element animate, that works: <svg width="500" height="650" > <rect ry=5 rx=0 x=150 y=100 width=90…
-
4
votes3
answers1096
viewsA: How to change a value of a literal Javascript object?
Missed to call the function in the object itself, as a method. The way you did, it must be giving an error because the function does not exist outside the object. In code, I mean this:…
-
0
votes1
answer116
viewsA: Doubt about $.getJSON and history.pushState
I will reply point by point on the historical part. As for the getJSON, I think it is a case for a separate question, as I already said in the comment above (do not take it badly, we are crazy for…
html5-historyanswered bfavaretto 64,705 -
2
votes2
answers106
viewsA: Variable scope problem in each method
The $.each (or jQuery.each) which you are using is for arrays and objects. For collections of DOM elements, use .each right in the collection: var filters = $(".filter_check:checked"); var…
-
21
votes3
answers2003
viewsA: In PHP the correct is Else if or elseif?
As none of the answers spoke of this, I thought it best to include another. It has already been said, and it is true, that for practical purposes elseif and else if are equivalent (except in syntax…
-
25
votes2
answers8570
viewsA: Get "waves" from sound or music frequency
To HTML5 Audio API 5 allows this type of visualization, with a lot of flexibility. Here is an adapted example of a tutorial from MDN, taking audio from an element <audio> and drawing the…
javascriptanswered bfavaretto 64,705 -
8
votes1
answer2150
viewsA: How do I take what’s copied on the clipboard and put it into a variable?
By pressing CONTROL+C in the browser, you will copy what is selected to the clipboard. Just before this copy occurs, the event is triggered copy, that you can intercept. Inside, check the value of…
-
5
votes3
answers2029
viewsA: Pass Google Maps API to JPG image
Google has a Static Maps API which are served as image. It’s very easy to use, just build the right URL and put as src image: <img src="https://maps.googleapis.com/maps/api/staticmap?center=São…
-
9
votes1
answer72
viewsA: String in php is a class?
Not. In PHP, string is one of the eight primitive types available. When you assign a string to a variable, it is not possible to invoke methods in it. It does not occur autoboxing in a corresponding…
phpanswered bfavaretto 64,705 -
6
votes4
answers673
viewsA: Large integers and cousins
I already I insisted enough on the comments for you to use a pre-defined primes table. Generating Javascript primes is not at all efficient, especially if you only need to draw one. If you need…
javascriptanswered bfavaretto 64,705 -
3
votes1
answer620
viewsA: Add Letter in a field with 20000 lines
Considering that the column is text type, and that this change will not cause harmful side effects (such as breaking foreign keys), the command is simple: UPDATE produto SET codigo = CONCAT('o',…
-
2
votes2
answers394
viewsA: How do I disable selecting text at the right click?
You can take advantage of the event that opens the context menu, and clear any selection from there: document.addEventListener('contextmenu', function(e) { window.getSelection().removeAllRanges();…
-
2
votes1
answer849
viewsA: How to get back data from a function via ajax?
At the end of this method test, before closing the function, add: $this->set('balance', $balance); This will leave a variable $balance available in your view test.ctp. On the Javascript side, you…
-
4
votes1
answer658
viewsA: How to make the tip of the "balloon of dialogue"?
Yes, and you need a separate element just for the arrow. For example, using a <div>: div { width: 12px; border: 6px solid transparent; border-right: 6px solid #f4bb00; }…
-
5
votes4
answers20055
viewsA: How to open a pop-up without using Javascript?
The best thing to do is to force the opening in another tab (or window, who decides is the browser): <a href="http://google.com" target="_blank">Google</a>…
-
10
votes1
answer832
viewsA: What is the baseline?
The concept really comes from typography. A baseline is the baseline where the text is based. If you are writing on a lined sheet, the baseline is equal to the agenda itself: Image source In the…
-
9
votes2
answers5494
viewsA: Foreach inside of foreach
You can’t grant a foreach with a string like you tried to do. You need to separate things: echo "<a href='#'>"; foreach($FetchFoto as $autorFoto) { echo "<img src='".$autorFoto["foto"]."'…
-
4
votes2
answers58
viewsA: Determine the direction of the roll in an element
The code works well and I don’t see how to optimize it if the goal is to detect the bearing direction at each step (i.e., in every event scroll, which is fired multiple times while the contents are…
-
1
votes1
answer212
viewsA: Cakephp constants are not recognized when accessing a webroot file
As you said in a comment, your file is loose in webroot of the project, so it is accessed directly, without going through Cake. That way, nothing that is Cake’s is initialized, including the…
-
3
votes1
answer24
viewsA: Contraindications in Iife’s
No, I see no problem in doing so. On the contrary, there are advantages, since you are not leaking variables to the global scope.
-
2
votes1
answer5553
viewsA: How to insert jQuery via HTML
This code is redundant. You have two options: 1. Insert this into the HTML header: <head> ... <script> jQuery(function($){ $("h3.symple-toggle-trigger").click(function(){…
-
16
votes2
answers151
viewsA: Name for anonymous functions
There are two objectives: Recursion: is a way to enable function expressions are recursive. The name defined for these functions is only available within themselves, and can be used for recursive…
-
12
votes2
answers280
viewsA: How to implement a library that has features similar to jQuery?
What you want is called chaining. You need to have an object (while in your code you have a function), and all its methods return the object itself. A simple example of the principle, using a…
javascriptanswered bfavaretto 64,705 -
1
votes1
answer166
viewsA: Directory organization in the Silex framework
Silex does not require any directory structure, you are free to use what you like best, which is most suitable for the project. If on the one hand this freedom is good (Silex does not impose…
-
8
votes2
answers4961
viewsA: Calculate how long it takes to execute a function
To measure runtime, with millisecond resolution, just compare the timestamp before after execution: function fn() { var teste = []; for (var i = 1; i <= 305; i++) { for (var x = 1; x <= 305;…
-
2
votes1
answer61
viewsA: Problem using function with truncated file
What you are doing wrong is passing your entire JSON to the function. It expects to receive only key content shapes. View code in operation here. I don’t know how you get this JSON, depending on the…
-
2
votes1
answer119
viewsA: How to attach a DIV to another DIV using DOM
Instead of document.body.appendChild(X); (that attached to the body), use: Y.appendChild(X);
javascriptanswered bfavaretto 64,705 -
32
votes1
answer33629
viewsA: What is the difference between ISNULL and COALESCE in a survey?
The main difference in functionality is that the COALESCE accepted n arguments, returning the first with no value NULL between them. The ISNULL accepts only two arguments, one possibly NULL, and…
-
1
votes1
answer109
viewsA: Add MYSQL constraint
Say the ID can’t be 1: $sql = "SELECT * FROM `login` WHERE account_id <> 1 order by `account_id` ASC"; Assuming that Ids are all positive, it can also be so: $sql = "SELECT * FROM `login`…
sqlanswered bfavaretto 64,705 -
0
votes1
answer43
viewsA: Running a function allocated to an object from a comparison in for
I reworked your code, commenting step by step. I also eliminated the jQuery dependency, the code uses pure Javascript only. I hope it helps. // Esta parte ficou quase igual var validadores = { // O…
-
15
votes2
answers11673
viewsA: Remove a property from an object contained in an array
You can use the delete to remove properties of objects within the array (which is what you have, two objects within the array bola. // Não esqueça o var! var bola = []; bola[0] = { peso:0.5,…
javascriptanswered bfavaretto 64,705 -
1
votes1
answer582
viewsA: Backup the database by clicking on a link
Mysql comes with a utility exactly for this, which is the mysqldump. Locate this file on the machine and save its path. In PHP you can run this utility with exec, and save the backup to disk. Saving…
-
3
votes3
answers512
viewsA: Create element only in the first mouseover
You can check if the <span> already contains a <map> at the end, and only create and insert the map if it is not already there: function mostra(){ var span =…
javascriptanswered bfavaretto 64,705 -
5
votes2
answers528
viewsA: setTimeout not executed in loop(each)
Contrary to what you’re thinking, the whole loop of each occurs immediately. Only what is within the "delayed" wheel setTimeout, asynchronously (as if it were "parallel"). Inside the loop, your code…
-
2
votes1
answer101
viewsA: How to detect changes of more than 15px in Resize Window
If I understand correctly, you want something to happen every 15 pixels of resize. As during resizing the window the event resize occurs several times, you need to create "milestones" in which saves…
-
4
votes2
answers292
viewsA: Undo error display on console
You can reset the console and its method log: window.console = { log: function(){} }; console.log('sumiu!'); But this only affects your direct calls to console.log. If the idea is to omit displaying…
javascriptanswered bfavaretto 64,705