Posts by bfavaretto • 64,705 points
902 posts
-
3
votes1
answer334
viewsA: Create a random combination with CSS classes using javascript or jquery
You can draw the classes from an array. Or rather, two, one for BG and one for the source, so you get some contrast. Example: var classesBg = ['fundoAzul', 'fundoVermelho', 'fundoVerde']; var…
-
2
votes3
answers73
viewsA: What is the best option to use in relation to performance
Warning: Unfortunately the jsperf, that would be the most practical tool to test what I say in my reply, has had stability problems, and I’m having trouble using it at the moment. So consider that…
-
7
votes2
answers320
viewsA: Click and "Decrypt" on jquery button
Your code includes a checkbox that stores whether the status of the button is "on" or "off". You can use this state to determine the color. For example: $('#button_on-off').click(function(){ var cor…
jqueryanswered bfavaretto 64,705 -
2
votes1
answer836
viewsA: Reload an Angularjs table from time to time
You can try the code below. What I did was to wrap in a "private" function the section that searches the data, and call this function both at startup, and at intervals determined by a timer: //…
angularjsanswered bfavaretto 64,705 -
6
votes1
answer1112
viewsA: Logical operators javascript
The operator and (&&) has greater precedence than the or (||). That means that in a sequence of ands and Ors, the ands are resolved before. Therefore the first version is interpreted as: X…
-
3
votes3
answers90
viewsA: Constant containing Array (matrix)
The manual answers: Until PHP 5.6, only scalar data (Boolean, integer, float, and string) can be put into constants. Starting with PHP 5.6, you can also use an array as a constant value. The use of…
-
6
votes8
answers794
viewsA: Mapping an array with possible subarrays as elements
You already have several solutions in the other answers, so I’ll just explain the problem of your code. The problem is in this excerpt: element.forEach(function(subElement){ return(subElement); })…
-
5
votes2
answers577
viewsA: Mysql, doubt about variables
The variables with @ sane user-defined variables, and have session scope. That is, it is valid from the moment the connection with the server is opened, until the closure of that connection. The…
-
2
votes1
answer55
viewsA: run updated loop with js returning another
Its function init only executes once, when the page loads. If you want the element send_string_array reflects the current state of the array map, need to update the contents of this element every…
-
6
votes4
answers329
viewsA: What’s wrong with my map version for a JS array?
The other answers are very good, but I missed saying one thing: why the hell do you want to create a function of map and calls her forEach? They are two different things! And it is very important…
javascriptanswered bfavaretto 64,705 -
2
votes1
answer382
viewsQ: How does Python interpret multiple comparison operators in sequence?
I found the following using a Python REPL: 3 == 3 > 2 => True Initially I thought it might be something related to the precedence of operators, however: 3 == (3 > 2) => False (3 == 3)…
pythonasked bfavaretto 64,705 -
5
votes1
answer3299
viewsA: Display div after a certain time, with setTimeout
<div id="mime"> <iframe style="border:none; overflow:hidden; width:605px; height:250px; float:left;" frameborder="0" scrolling="No" src="http://migre.me/qaksC"></iframe>…
-
7
votes1
answer67
viewsA: How to get the value of a property using variable as name?
The LANG.A of your example looks for a property called A in the object LANG. Already LANG[A] finds a property whose name is the variable value A, that is to say, 'ABC' - is therefore equivalent to…
-
9
votes1
answer3133
viewsA: How to declare several conditions within an if
Like the qmechanik said, would need to be ($var3 == 1 || $var3 == 3 || $var3 == 5 || $var3 == 7 || $var3 == 8 || $var3 == 12) That’s because the way you did it, 1 || 3 || 5 || 7 || 8 || 12 is…
phpanswered bfavaretto 64,705 -
3
votes1
answer75
viewsA: How to Persist Progressive Discount Information?
If an order can have N discounts, you can use a table descontos sort of like this: id pedido_id valor_desconto -------------------------------- 1 1 5 2 1 10 3 1 15 4 2 5 ...…
databaseanswered bfavaretto 64,705 -
5
votes2
answers1489
viewsA: Difference between two PHP dates in 31, 28 and 29 day months
Use the property days instead of d: $time1 = new DateTime('20150501'); $time2 = new DateTime(); //data atual $interval = $time2->diff($time1); echo $interval->days; http://ideone.com/zK0P2E…
-
2
votes3
answers867
viewsA: Reset the Alert function
The functions alert, prompt and confirm, native to browsers, they have a behavior that is impossible to reproduce: they block the processing of any later Javascript code until they are dispensed…
javascriptanswered bfavaretto 64,705 -
1
votes2
answers596
viewsA: How to display the content of a queue?
Like Queue implements IEnumerable, you can iterate all elements with foreach: Queue<string> fila = new Queue<string>(); fila.Enqueue("Teste 1"); fila.Enqueue("Teste 2");…
c#answered bfavaretto 64,705 -
5
votes2
answers61
viewsA: Doubt about decrement operator
Only Return wouldn’t be the same? Not!!! The $idade-- subtract 1 of the value of $idade. Amounts to: $idade = $idade - 1; Therefore, if you withdraw the $idade--, the value returned by its function…
phpanswered bfavaretto 64,705 -
8
votes3
answers48474
viewsA: Getting input value with jQuery
The problem is that you are picking up the value before it exists. Leave to pick up the .val() only in the focusout: var vendaMediaMensal = $("#vendaMediaMensal"); vendaMediaMensal.focusout(…
jqueryanswered bfavaretto 64,705 -
1
votes2
answers1648
viewsA: Mysql UPDATE multiple fields under the same condition (IF or CASE)
The syntax for multiple fields is: UPDATE [tabela] SET campo1 = valor1, campo2 = valor2 ... WHERE ... As for your query, it seems that it could be reformulated like this: UPDATE leilaov SET seconds…
-
4
votes1
answer326
viewsA: SELECT with sequential counter does not accept LEFT JOIN
The reason for the error is in mysql manual: INNER JOIN and , (comma) are semantically equivalent in the Absence of a Join condition: Both Produce a Cartesian product between the specified Tables…
-
2
votes1
answer146
viewsA: Is it possible to pick up a title from an image using "Getelementsbytagname"?
This shows the title of all images on the page: var imagens = document.getElementsByTagName('img'); for(var i=0; i<imagens.length; i++) { alert(imagens[i].title) } Considering the code you…
-
5
votes5
answers26037
viewsA: Accentuation in the JSON
That’s not a problem, you agree with specification of JSON: In Javascript special characters can be used with Unicode escape codes (even in variable names!) in format \uNNNN, and JSON works the same…
-
3
votes2
answers1865
viewsA: Update JSON value with Javascript
What you have there is an array, with one (and only one) object inside. Then you need to access the first position of the array before you can access the property dM of the object: data[0].dM =…
-
7
votes2
answers129
viewsA: What is the difference between $var = Function() and Function var()?
What you have in the first example is a anonymous function, which is assigned to the variable $var and then invoked. The variable has a name, but the function itself does not have. In the second…
phpanswered bfavaretto 64,705 -
8
votes2
answers406
viewsA: Object declaration in Javascript
No. This is a function. It could be called informally "class List", if the intention is to use it as a construction function, with the operator new. In this use, then yes you will be creating an…
-
5
votes1
answer48
viewsA: How do nodes work in javascript?
THE GIFT (Document Object Model, or "document" object template) is actually a separate API, present in browsers, but not part of the Javascript language itself. The structure is very simple, it’s a…
javascriptanswered bfavaretto 64,705 -
13
votes1
answer161
viewsQ: Should translation dictionaries use the original strings as keys?
I have already built some systems and multilingual websites, and in the tools I have known there seems to be a tendency to use the string in the application’s original language (usually English) as…
-
0
votes1
answer96
viewsA: Do not always use the boot attached
Assuming that the button4 whatever sends the email, if you do not want attachments you need to check if your attachment field is empty. For example: private void button4_Click(object sender,…
c#answered bfavaretto 64,705 -
5
votes2
answers547
viewsA: PHP Text Interpreter
I see at least three points that can be optimized with ease: The if more from the outside seems unnecessary. The strtolower(removeAccents($qt)) may end up running more than once (4 times if you type…
phpanswered bfavaretto 64,705 -
1
votes1
answer964
viewsA: Highlight table row under cursor with Pure CSS
You can use this: tr:hover:nth-child(2n-1) td {background-color: #ffff99; } That will overwrite this rule of the Pure: /* nth-child selector for modern browsers */ .pure-table-striped…
-
6
votes3
answers16826
viewsA: How to create an array within another array with jQuery
There are several ways. The one closest to the code you put in (which is PHP, right? ), are nested literal objects (if keys have names), or nested arrays (numeric keys). Nested literal objects var…
-
2
votes1
answer485
viewsA: How to Take an Auto Increment Id and Attach it to a Variable in the same Index
As far as I know, this is not possible. You need to first do the INSERT, and then a UPDATE: UPDATE agenda_saidas SET url = CONCAT(url, id) WHERE id = LAST_INSERT_ID()…
-
5
votes1
answer1085
viewsA: Calling PHP method with ajax
The code is almost that, but the parameter data must contain an object (while in your code there is a syntax error, hehe): $.ajax({ url: 'script.php', //caminho do arquivo a ser executado dataType:…
-
7
votes3
answers779
viewsA: Passage of parameter C#
Because your request uses the HTTP GET method, the parameter must be part of the URL itself. Then the URL will have the following format: /Solicitacao/ConsultaSolicitacao/id It seems simple to…
-
2
votes2
answers1817
viewsA: Place Json value on variable
The $(this).val(valor) fills the field and returns the corresponding jQuery object, i.e., $(this). That’s why Alert shows this text object representation that you received. If the field is being…
-
2
votes1
answer472
viewsA: How to replace an attribute of an HTML snippet that is string?
Convert the string to a DOM element, which you can normally cross through: var teste = $(div); teste.find('.filho').attr('tabindex', 10); teste.find('.search').attr('tabindex', 20); // Depois você…
-
2
votes1
answer2858
viewsA: How to pick up field values with javascript
This works on all browsers, but I would say it’s old-fashioned, because it’s from the time of the so-called "DOM Level 0" when there was no formal specification of how this kind of thing should…
javascriptanswered bfavaretto 64,705 -
2
votes3
answers249
viewsA: Set JS to calculate the size of a div
I want when the site opens each div to have at least the screen size You can achieve this by putting height: 100% in these Ivs. But beware: all elements above them in the hierarchy also need to have…
-
4
votes1
answer5125
viewsA: How to print HTML background colors with CSS
In Chrome and Safari (and possibly other Webkit-based browsers), there is the non-standard property -webkit-print-color-adjust, which may be defined as exact to force the printing of background…
-
4
votes1
answer132
viewsA: Put stretch between parentheses
Put the condition of bedrooms in your array of OR: $what_or['bedrooms >= ?'] = $params['bedrooms']; $what_or['suites >= ?'] = $params['bedrooms']; Then adjust the part that mounts the SQL like…
phpanswered bfavaretto 64,705 -
4
votes1
answer91
viewsA: Why is my radio input returning "on"?
Your radios don’t have the attribute value, you seem to have used val in place. When radios have no value, this value is posted "on". You seem to be wanting to build something like this: <label…
-
2
votes3
answers1551
viewsA: Keep the height of a div block proportional to its width
The solution seems to be really use padding-top, as suggested in the @Renan comment and the @Jeffersonalison response. The CSS padding is proportional to the container width. #a { width: 35%;…
-
13
votes8
answers17275
viewsA: Difference between while and for
In my view, the for is syntactic sugar for a common use case of while, which is to use a variable as a counter and a condition based on the value of that variable (i.e., stop when the variable…
-
9
votes2
answers33357
viewsA: How to get the current date in Mysql?
Just use NOW(): CREATE EVENT e ON SCHEDULE EVERY 1 HOUR DO UPDATE anuncios SET estado=3 WHERE dataexpiracao > NOW()…
mysqlanswered bfavaretto 64,705 -
1
votes3
answers685
viewsA: Doubt with Getdate()?
You are getting this result because the current time (caught by GETDATE()) is being considered (is a value of type DATETIME). Thus, today at noon is larger than today at midnight (which seems to be…
-
8
votes5
answers294
viewsA: Problem with calculator program
Beyond the problem of switch('op'), that should be without quotation marks as already mentioned in the comments, your scanf is not consuming the input the way you imagine. Let’s test for example the…
canswered bfavaretto 64,705 -
2
votes1
answer112
viewsA: Convert JS timestamp to PHP
Javascript generates value in milliseconds, and PHP in seconds. To compare them, multiply the PHP value by 1000, or divide the JS value by 1000 and take the whole part.
-
13
votes4
answers114
viewsA: Why is this SQL statement incorrect?
The AND takes precedence over the OR. So your criterion is understood like this: (categoria = 'Vestidos' AND cor = 'Branco') OR cor = 'Rosa' You need to put the parentheses in the right place to…
sqlanswered bfavaretto 64,705