Posts by Rui Pimentel • 2,790 points
54 posts
-
7
votes0
answers73
viewsQ: How did Microsoft manage to customize the title style of the tab?
Looking at the new Microsoft page for Windows 10, at least in Ubuntu 14 / Chrome 43, I realized that the font size of the tab was larger than the source of the other open tabs. In Firefox 38, this…
-
4
votes3
answers424
viewsA: How to check if a value starts with a bar followed by a message?
If valid strings are in the form /{mensagem}, with the string value {mensagem} already saved in a variable, No need for Regex! :) var str = "/msg válida"; var msg_valida = "msg válida"; if(str ==…
-
1
votes2
answers2429
viewsA: Is it possible to call Function without being by onclick?
Once declared, a function can be called in any Javascript snippet. For the common purposes of Internet scripts, it can be said that almost always function calls and other operations are made in…
-
3
votes2
answers1298
viewsA: Remove array from an array
You can use the function filter(fc), whose parameter fc must be a function that takes each element of the array as argument (in other words, a function fc(el)); in your case, each element of the…
-
1
votes1
answer113
viewsA: How to fill the data of a tree-shaped element?
Just to not be unanswered, I decided to implement the algorithm in Javascript. The comments explain better than an introductory paragraph, but I note here that this code can be easily adapted to any…
algorithmanswered Rui Pimentel 2,790 -
1
votes1
answer164
viewsA: Improve javascript function that enables checkbox
The solution As the hierarchy pattern is very clear (there is always a "checkbox-proximity" class label encompassing a checkbox; the ID of this checkbox is related to the ID of the <input />),…
javascriptanswered Rui Pimentel 2,790 -
2
votes2
answers5775
viewsA: Dynamic array in Javascript
Basically everything you want to do with associative array can be done with objects. To print, for example, you can iterate over the keys (attributes) of the object, as in the following example: var…
-
3
votes1
answer2855
viewsA: Doubt in array n rows x 3 columns
An array, in Javascript, can be simulated through nested arrays. What is called line or spine is merely symbolic and abstract; I specifically like to think of the lines as being the positions of the…
javascriptanswered Rui Pimentel 2,790 -
3
votes3
answers10282
viewsA: How to navigate a children and a div with Javascript?
It was almost right; you just forgot to scroll through the child array instead of the element attributes. Additionally, to get only the DIV’s, just check the value of the tagName of every child. See…
-
1
votes1
answer87
viewsA: Building a function name and executing it
Accessing object attributes as associative array Javascript allows you to access attribute values an object through a mechanism similar to -- but not -- to associative arrays: var db = { make: { //…
-
4
votes2
answers14517
viewsA: Get file name in input file
In pure Javascript, you can get the file name by manipulating the Fileupload Input object, as an example below: var div = document.getElementsByClassName("botaoArquivo")[0]; var input =…
-
0
votes1
answer262
viewsA: How to pass variable to AJAX?
I believe it is the case to print, from PHP itself, the music code on the add button. But before, only one thing I noticed: it is id or class, in the first line of the section below? echo "<a…
-
4
votes3
answers1346
viewsA: Generating an image based on other images
Possible, yes, with the Canvas API (HTML5). However, for security reasons, it is not possible to display the result of gluing to a tag <img>, also do not download, case at least one of the…
-
5
votes2
answers61
viewsA: Define property based on others during object creation
As explained by @Sergio, the object is not yet built in memory and therefore there is no pointer to its content yet. If it is really necessary to declare the attribute nome_completo within this…
javascriptanswered Rui Pimentel 2,790 -
8
votes3
answers657
viewsA: How to make the page load only after the return of getJSON?
So, in my view, it is the server who should perform the search and embed the data directly in the page that will be served (as a result of server processing). In most cases (and I say this only…
-
3
votes3
answers1981
viewsA: Rescue the index of an object with a certain attribute within an object array
An option I would adopt: var indice = listaImagens.indexOf(listaImagens.filter(function(obj){ return obj.idCategoria == 2; })[0]); Jsfiddle: http://jsfiddle.net/ruipimentel/cfLmLrex/ 1. Explanation…
-
2
votes6
answers2305
viewsA: Transform results combination function into a dynamic function
To generate all possible combinations, including repeated numbers, use the section below. The parameter gama denotes the number of options for each cell (ie each cell will be filled with a value of…
-
6
votes1
answer717
viewsA: Function statement in Javascript
In practical terms, the only difference is in relation to the code flow; if you try to call a function declared by Mode 1 (var funcao = function(...){...}) before this line has been executed, you…
javascriptanswered Rui Pimentel 2,790 -
2
votes2
answers207
viewsA: How to force the '.on("input")' method via script?
If the goal is simply to call the function, why not give it a name and call it directly? function callback(){ alert("oi"); } $(document).on("input", "#textbox", callback); callback();…
-
3
votes2
answers377
viewsA: How to get the text of a radio button?
If you make a small change to your PHP, the radiobutton text will be printed inside a tag (for example: <label>, which by the way is a good one, in terms of usability), just add to your…
-
1
votes2
answers166
viewsA: Absolute position does not work in a fixed menu
Add the z-index:999; to class menu also. .menu { ... z-index:999; } Edit: to document for posterity: The z-index is equivalent to the position in the Z coordinate; the Z axis is taken as the one…
-
2
votes1
answer371
viewsA: How to take multiple data from a page and display separately with AJAX
One of the solutions, and the one that I consider more reliable (in terms of possible entries that can generate confusion in the logic of the script), is to pre-format the answer still on the server…
-
10
votes2
answers163
viewsQ: What is differential inheritance?
I was reading this article in the English OS and came across the term Differential inheritance. Which, exactly, is differential inheritance? It is possible to have a minimum example, preferably in…
-
10
votes3
answers4991
viewsA: Back to Top of page
The easiest way is without any script/animation - unlike this link you gave of example. Shortly after the <body>, include a small anchor: <body> <a id="topo"></a> ... Then…
-
2
votes3
answers1211
viewsA: How to modify form fields if user input is invalid compared to regular expression with Jquery
By complementing the @bfavaretto response, to ensure that the form does not file an error on startup, you can use another method. A small CSS together with a Javascript+jQuery is enough: .invalido {…
-
6
votes4
answers1147
viewsA: Mark checkbox if user writes input text in a table
I suggest slightly adapting your HTML, including a class (say: CaixaMagica) in each text box and a class in each checkbox. Your HTML will look like this: <table> <tr> <td>…
-
5
votes2
answers2689
viewsA: How to access an element within another HTML element with pure Javascript
Selectors a la jQuery: Are available on Document and in all elements; work similarly to jQuery, and are well supported by the most modern browsers. In IE, by the way, are available from version 8.…
-
13
votes2
answers2610
viewsA: When to use prototype (JS)
Okay, let’s make a few points... It’s just three big cases It all comes down to three big cases: 1: Function of the prototype The following situation illustrates the declaration of a prototype, with…
javascriptanswered Rui Pimentel 2,790 -
3
votes3
answers3244
viewsA: Calling a method from a Javascript class (OOP)
If you can add the line return this; as the last of the function/class declaration SDK, then it is possible to call the desired function instantiating (var a = new SDK(); a.start();) or not the…
-
2
votes1
answer421
viewsA: Calling external file by Div
Have you ever tried to capture the ID this way? If there is only one <div> with this ID, this is the easiest way to do. function picasa_callback(obj) {…
-
8
votes3
answers1242
viewsA: Transforming jQuery code into Javascript
whereas: jQuery itself, at least in version 2, does not support browsers well ancient; IE6, IE7 and even IE8 are getting rarer every day; The work to make the code really compatible with these…
-
1
votes1
answer11910
viewsA: Body Mass Index Calculation (BMI)
Hello, the script is loaded correctly. However, if you open your browser console (shortcut: F12 for most of them), you will see that an execution error occurs, which prevents your run-away function.…
-
30
votes4
answers72185
viewsA: What is a callback?
When an event (click on a button, page load completed, mouse over any element, etc.) happens, the browser warns all listeners (listeners), calling your functions Calback.…
-
1
votes2
answers85
viewsA: Format Date in javascript for "from here to Xd Yh zm"
Hello, I will try to be as didactic as possible, so that more people can take advantage of this answer in the future. Although you CAN start by selecting minutes, then hours and then days, it is…
-
2
votes5
answers23429
viewsA: Calling js function in another file - Dependency between Javascript scripts
You should expect the entire page to be loaded to have access to the DOM elements, which probably happens within your function exibirModal(). So try to take advantage to make the call in a function…
javascriptanswered Rui Pimentel 2,790 -
2
votes1
answer340
viewsA: How to clean only the current tab!
You need to insert (preferably into a separate .JS file) the following script, which implements the technique popularly known as AJAX. function atualizar(divResultado, url){ // Conforme tutorial da…
-
5
votes2
answers757
viewsA: Angularjs Directive - Good practice
From what I read (and didn’t get to test!), the only two methods compatible with older versions of IE are the first two: directive as attribute declaration and as class. <div…
-
1
votes1
answer76
viewsA: Control Javascript page content according to who is ordering
A question much like your was done at Stackoverflow in English. A response, I will translate (because we are in the OS in Portuguese) freely the following is particularly complete, in my opinion,…
-
2
votes2
answers97
viewsA: How to add javascript files according to viewport/device?
There are two ways: server-side or client-side. Server-side It depends heavily on the language. Some already have well-established libraries for client detection from the HTTP request header. If…
-
8
votes9
answers166445
viewsA: How to hide/show a div in HTML?
Its variable disp is just getting a COPY of current value of the "display" attribute. Change the variable value nay will change the value of this attribute "display". Therefore, its function should…
-
1
votes2
answers23140
viewsA: Change RG mask
In pure Javascript and without any validation, the function code should look like this: function Rg(v){ v=v.replace(/\D/g,""); v=v.replace(/(\d{2})(\d{3})(\d{3})(\d{1})$/,"$1.$2.$3-$4"); return v; }…
javascriptanswered Rui Pimentel 2,790 -
1
votes2
answers449
viewsA: How to know that the file has reached the end with Filereader()?
There’s a difference between carry and execute. I believe you’ve already succeeded carry correctly all files, in sequence, to memory. Filereader functionality ends there; Javascript has access to…
-
3
votes2
answers772
viewsA: How to search for a device on an internal network using Javascript and/or Node js
In Node JS, it should not be so difficult; if the idea is simply to eliminate the need for the user to deal with IP numbers, it is enough that there is a Node JS server that can access and return…
-
1
votes2
answers5780
viewsA: Perform an action after the change has been made
It’s just encapsulating in a function, just to keep the organization going, and then calling Function inside your callback: $(document).ready(function() { function doAfterChange(){…
-
1
votes1
answer2244
viewsA: How to handle addeventlistener event click in javascript
One possible solution is to remove the Istener after use, and add another referring to the next state. This can be done within your checkClick function, after you validate that the click was…
-
2
votes1
answer174
viewsA: Use of callback to work with asynchronous javascript
I believe the code is already very good. I liked the asynchrony! A modification in the sense of potentiating it (asynchrony), with advantages and disadvantages that I will already discuss, would be…
-
3
votes1
answer186
viewsA: Change specific string fields in Javascript
You only need a simple substitution with regular expression; the verification of existence or not is already on account of the method replace. An example of replace in Javascript: var string = "Este…
javascriptanswered Rui Pimentel 2,790 -
2
votes1
answer3989
viewsA: Block website rotation in mobile version
The colors are just for you to have an idea. That didn’t sound very good, at least on my Moto X (Chrome, Android 4.4). <html> <head> <meta charset='utf-8' /> <title>Teste de…
-
16
votes1
answer2705
viewsA: How to sort array of strings disregarding accents?
Use localCompare as per the documentation found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort var items = ["Cátodo", "caule", "casca"];…
-
8
votes7
answers46159
viewsA: Remove repeated elements within a Javascript array
To do with pure Javascript, as answered in this link: https://stackoverflow.com/a/9229821 uniqueArray = myArray.filter(function(elem, pos, self) { return self.indexOf(elem) == pos; })…
javascriptanswered Rui Pimentel 2,790