Posts by bfavaretto • 64,705 points
902 posts
-
3
votes1
answer3362
viewsA: How to create an empty block?
You do not need invisible elements to create these spaces. In the case of your last example, simply apply margins in the div .vitrine: <div class="vitrine"></div> .vitrine { height:…
-
12
votes1
answer193
viewsQ: When is it useful to capture DOM events?
The events of the DOM traverse the document tree up to his target, with a phase of catching and a phase of bubbling. The default behavior when creating a Listener with addEventListener is to treat…
-
17
votes1
answer50551
viewsA: Capturing an element’s id with javascript click
If you are using Javascript inline (as in <div id="a" onclick="f()">...), does not. You would need to pass the id on the function call itself. But using JS inline is contraindicated, not only…
-
5
votes2
answers124
viewsA: How to use FOR-generated number in the name of a variable?
Although it is possible, avoid creating variables with dynamic names! In these examples, you can very well use arrays, where each value can be obtained by the index. When you say [i], is creating an…
javascriptanswered bfavaretto 64,705 -
2
votes3
answers3897
viewsA: Update in two columns, two tables
I think that it is not possible to do this with JOIN between the tables, because after the first UPDATE in one of the tables, the criterion of JOIN would no longer be met (example). But I propose…
-
3
votes1
answer1009
viewsA: Promises as function return in Node.js
There are some parts of your code that I don’t quite understand, but to answer the question, return a object and not a function: function validateLogin( pemail, ppwd ) { return { success: function()…
-
19
votes2
answers1375
viewsA: What is it and what are the advantages of Currying?
Currying and partial application It’s extremely common to find definitions and examples of currying that actually refer to partial Function application, or partial application of functions. For…
-
2
votes4
answers354
viewsA: Query about parameters and function call
If the second function is in the global scope, just invoke it from the object window. Also remember to wait for the loading of the script as indicated in the other replies: function funcao_um…
javascriptanswered bfavaretto 64,705 -
6
votes1
answer1256
viewsA: Invalid parameter error when doing PDO perform action
I see some problems (maybe not all) in your use of PDO: Parameters serve to override values, not snippets of a clause. That is: you cannot use WHERE :where, needs something like WHERE coluna =…
-
4
votes2
answers235
viewsA: Columns in percentage not aligned
The problem is that the widths are relative to the container. This remaining 1% is not being enough to accommodate the 60px margins. The simplest solution (but not working on IE9 and above) is to…
-
1
votes1
answer79
viewsA: Cakephp: Why is Model not being loaded correctly?
Apparently, your solution to inflections is not working, but the $uses nor would it be necessary. Your attempt with $uses was incorrect, because the value of this property needs to be an array. Try…
-
1
votes1
answer1195
viewsA: Field 'lastiplog' doesn’t have a default value
Your INSERT does not include the column lastiplog, and Mysql does not know what value to store in it, since it cannot be NULL nor is there a default value set. See your column definition in CREATE…
-
3
votes1
answer90
viewsA: Problems checking out Empty()
Remove the spaces around the value before applying the empty: $valor = " "; $valor = trim($valor); if(empty($valor)) { echo "Sim, está vazio"; } https://ideone.com/Afl1nm To function trim removes…
-
5
votes1
answer338
viewsA: How to check the existence of multiple values in a string with Javascript?
One way to do it is to use Array.prototype.map to apply the indexOf each item in the array. For example: var string = "Oberyn se vinga de Sor Clegane"; var buscar = ['vinga','de','Clegane']; var…
javascriptanswered bfavaretto 64,705 -
5
votes4
answers4583
viewsA: Check for image return via Javascript
You can use a Library for the event onerror: <img src="http://pbs.twimg.com/profile_images/438827041199099904/ZLjBL8Tg_normal.jpeg" alt=""/ id="teste"> <script>…
-
4
votes2
answers1230
viewsA: Form action for same page or different page?
There is no "good practice", "right" or "wrong". Use as you see fit. If you submit to the same page, you need to redirect if you pass validation; if you submit to another page, you need to save the…
-
6
votes2
answers208
viewsA: How to change the style of superior brothers?
Cannot do by CSS. Sibling selectors + and ~ only allow selecting later elements in the DOM. For example, it is possible to select the second gear in the first with #start:hover ~ figure, but…
-
4
votes4
answers175
viewsA: Problem assigning HTML with . text() and . html()
The method .text() works just like that, rips off any HTML content and deals only with text. I don’t understand your restrictions, but you need to use .html() in place of .text(): function start(){…
-
5
votes5
answers9733
viewsA: How to get the index of a javascript object searching for the value?
You need to iterate all object properties (except inherited ones), until you find the value of the one you want: function chavePorValor(obj, val) { for(var chave in obj) { if(obj[chave] === val…
-
10
votes1
answer733
viewsA: How to send and process N separate forms with ajax without refreshing the page?
First of all, you cannot have multiple elements with the same id, as @Andrey commented above. Fix this in your HTML or it will be invalid (apart from the problems you will have when trying to locate…
-
6
votes3
answers529
viewsA: How to replace the last appearance of a character?
With Regex you can do it like this: var str = "Mussarela, Presunto, Calabresa, Tomate, Ovos, Pimentão, Cebola"; str = str.replace(/(.*), (.*)/, '$1 e $2'); console.log(str); // "Mussarela, Presunto,…
-
3
votes1
answer36
viewsA: Questions about Markup Validation errors W3C
The validator does not have access to your PHP files, only the HTML it generates. The error is on line 233 of this HTML. Look at the HTML snippet of this line and look (manually) for the PHP that…
-
28
votes3
answers624
viewsA: Analysis and Project in Javascript
A starting point for organizing and structuring your Javascript code is the module Pattern. It is about isolating your code in smaller portions (modules). The main advantages of this: Keep the…
-
5
votes3
answers307
viewsA: How do I use Python to search and store data from the Stack Overflow API?
The Stack Exchange API is all Restful, meaning you only need to make HTTP requests for a given URL, and you get a JSON response. There is no official Python client, but Renan found one in Guthub. So…
-
10
votes4
answers6348
viewsA: Detecting Line Break
Do not use literal line breaks, use \n and a safeguard for the \r: \r?\n. This would work with Unix-style line breaks (\n) and Windows (\r\n). The part of match then it would look like this:…
-
46
votes1
answer7672
viewsA: How does asynchronous programming work in Javascript?
Asynchronous programming is one of the main points of the language precisely because Javascript runs in a single thread. If there is only one thread to execute your code, you need to avoid as much…
-
10
votes3
answers1415
viewsA: When should I use elements '<ul>'?
The specification of HTML5 defines ul so (free translation): The element ul represents a list of unordered items; that is, a list whose meaning does not change if the order of the items that compose…
-
4
votes1
answer1901
viewsA: Shellrun using CMD to open mysql
You need to pass the option -e or --execute followed by the command you want to execute. For example: mysql.exe --host 192.168.0.50 --user root --database=sinval --password=bla --execute "SELECT *…
-
6
votes2
answers456
viewsA: Creation of tables with Database scripts
What kind of problems can arise with this method I use? One obvious problem that occurs to me is having to escape all the double quotes (") within your SQL statements (for example, in a string being…
-
4
votes2
answers149
viewsA: Function jQuery to hide elements
Treat it to an ancestor of the element you want to hide: $(document).on('click', function(e){ // verifique se o clique veio de dentro da sua janela. // para isso use e.target (a origem do clique).…
jqueryanswered bfavaretto 64,705 -
6
votes2
answers4748
viewsA: Validate and change user password with PHP
There’s a logic error here: if (($senha_atual != $senha_banco) && ($senha_nova != $confirme_senha) ) This is only true if the person misses both, that is, wrong current password + new…
phpanswered bfavaretto 64,705 -
5
votes2
answers438
viewsA: How to improve code workflow without using synchronous ajax?
If I understand correctly, the code stream posted, with the use of asynchronous ajax, is as follows: Button clicked, adicionarNumero is called. JSON (adicionar.json) received, atualizaTabela is…
-
4
votes1
answer1174
viewsA: Button that expands in Hover with CSS Transition
One of the possible solutions is to force the text inside the button to occupy only one line. You can do this by adding white-space: nowrap; overflow: hidden on your button: h2:before { content:…
-
9
votes4
answers6633
viewsA: What is the difference between pre and post increment in Javascript?
The behavior of these increment operators is related to something I mentioned in my answer to How does this if/Else work with "?" and ":"?. Imagine a line containing only this: i; We say it doesn’t…
javascriptanswered bfavaretto 64,705 -
55
votes7
answers87300
viewsA: How to validate with regex a string containing only letters, whitespace and accented letters?
If the target is just the common English accents, it’s easy to list them one by one. I would do a regex with the following blocks: A-Za-z upper and lower case without accent áàâãéèêíïóôõöúçñ:…
-
3
votes1
answer473
viewsA: Extract data from a javascript array
I can’t say for sure because the code you posted is invalid (several quotes are missing), but I imagine you’re behind it here: newObject.idCrip = JSON.parse(data[0]); This works if you have that…
-
5
votes2
answers329
viewsA: Change Href with jQuery
You tried a simple replace? Whereas you have already obtained the URL: var url = "/checkout/cart/add?sku=17839&qty=1&seller=1&redirect=true&sc=1"; url =…
jqueryanswered bfavaretto 64,705 -
1
votes1
answer210
viewsA: Explanation about a JSP command
StringUtils.isBlank returns true if the string passed is empty (""), contain only spaces (or other characters considered whitespace), or for null. Otherwise, it returns false. In your code, you have…
-
3
votes1
answer2989
viewsA: How to make a horizontal list of images that does not break?
There is more than one way to solve this, and it is usually done by Javascript. But there’s a simple way to solve by CSS that I really like, and I’ll explain here. As their images (in this case the…
-
7
votes3
answers8073
viewsA: Concatenate a link within a href attribute with a variable?
Set a global variable and use the operator + to concatenate: <script> var teste = "blabla"; </script> <a href="#"…
-
0
votes2
answers270
viewsA: Order by on a Count in another table
The base is a query with JOIN between the two tables. You must also group by item, and sort by the sum of the evaluations: SELECT Item.id, Item.nome, SUM(Avaliacao.avaliacao) AS positivos FROM Item…
-
15
votes4
answers4778
viewsA: How do value types and reference types work in Javascript?
Javascript has no difference of types. All variables are instantiated with the keyword var. Javascript has a type system When you store a value in a variable, that value has a type. The type of a…
-
57
votes1
answer1802
viewsA: How do prototypes work in Javascript?
The chain of prototypes It’s quite simple actually. Each object has a reference to a prototype, which is always another object, or null. This object, in turn, also has a prototype. It then forms a…
-
3
votes1
answer145
viewsA: Feed Hidden field by clicking on a table column
Since you are injecting this HTML into the document, it is safer to use delegation (replace the selector I used below with something that selects the table, or the nearest ancestor that already…
-
15
votes3
answers10821
viewsA: How to delete folders, subfolders and files?
In the PHP manual has a example recursive function that does this (despite using ternary operator in a way I don’t like): public static function delTree($dir) { $files = array_diff(scandir($dir),…
phpanswered bfavaretto 64,705 -
2
votes2
answers2139
viewsA: Filter String field snippet in Mysql
Considering only the Brazilian ZIP codes, as you said in the comments, you can use operations on strings to extract the numerical part, and REGEXP to filter results that do not contain Brazilian Zip…
-
3
votes2
answers156
viewsA: Is it possible to have more than one CSS rule for an "img" in a "div"?
With CSS you can automatically adjust the images to a fixed area. For example, in an area of 400px by 300px: img { max-width: 400px; max-height: 300px; }
-
1
votes1
answer263
viewsA: Chrome Extension: How to force a script to start only when the previous one is finished?
According to the documentation, the method executeScript accepted as third parameter a callback that runs when the script ends. So you can do so: chrome.tabs.onUpdated.addListener(function(tabid,…
-
7
votes3
answers228
viewsA: How to do repeating background with sprites?
I would use CSS gradients like @Sergio and @Paulomaciel suggested. But if you really want to use images, they need to be stacked in your spritesheet, which can be 2px per 100px: Then just move the…
-
6
votes3
answers2852
viewsA: How to force a download with ajax?
If I’m not mistaken, what you’re doing actually works in some browsers, but not in others. An alternative is to continue making the request ajax, and save the PDF to disk instead of trying to serve…