Most anwered "javascript" questions
Use this tag when the question refers to some feature, information, or problem that relates exclusively to the Javascript language (not to be confused with JAVA). Javascript is an implementation of Ecmascript, a dynamically typed, object-oriented, prototypical-inherited language. It is used for client-side scripting, but can be run in desktop or server-side applications using tools such as Node.js.
Learn more…26,588 questions
Sort by count of
-
42
votes14
answers126839
viewsPhone Mask Using jQuery Mask Plugin
I need to change the "-" position on the mask. <label for="telefone" >Telefone</label> <input style="width:25%; margin-right:25% " type="tel" name="telefone" id="telefone"…
-
78
votes12
answers208289
viewsHow to format date in Javascript?
I want to play the current date on one input, but in the "Brazilian" dd/mm/yyyy. My code: var data = new Date(); dataFormatada = ????? $("#Data").val(dataFormatada);…
-
40
votes12
answers79762
viewsFormatting Brazilian currency in Javascript
I have the following variable: var atual = 600000.00 ; Here we have the value six hundred thousand in American standard, I would like when I print on the screen to look like this: 600.000,00 I’m…
javascriptasked 7 years, 11 months ago Lennon S. Bueno 2,182 -
143
votes10
answers34548
viewsWhat is the difference between the == and === Javascript operators?
I have the following Javascript code: var x = 0; if (x === false) { // não acessa } if (x == false) { // acessa } Why the expression with the operator == returns true and with the operator ===…
-
1
votes10
answers5627
viewsFunction that returns if one can go to the database with true/false?
EXERCISE: Set the function possibleIrAoBanco, take two parameters, the first is diaDaSemana (string) and the second horaAtual(number), the function must return true, only if the database is open.…
-
16
votes9
answers27569
viewsHow do I read Javascript URL values (Querystring)?
When accessing a page, for example /item?tipo=1&nome=po%C3%A7%C3%A3o%20de%20cura How do I get these URL values, decoding appropriately?
-
123
votes9
answers13997
viewsHow to create a website without reloading every click on a link?
I’m looking to develop a site that runs all in the same file, but I’m not sure how to look for study material for this. Thus: Normal site->I’m on the Index.php page. When I click on the…
-
34
votes9
answers166445
viewsHow to hide/show a div in HTML?
How do I make a Javascript that shows/hides a div in HTML? I tried like: function Mudarestado(divid) { var disp = document.getElementById(divid).style.display; disp = "none; // (ou disp = "block") }…
-
9
votes9
answers2096
viewsHow to assign a function with parameters to click without executing it?
Explanation: I have an application that has by default an event mostraGrupos() and when it is executed, at the end it detaches itself from the element and tries to assign the function…
-
37
votes9
answers34793
viewsInput type="password" with password display eye
I need to put a <input type="password"> with that eye of the reveal password, but it has to work as follows: User clicks on the eye and when dropping hides the characters again. Follow an…
-
38
votes8
answers14487
viewsHow to create a copy of an object in Javascript?
I have an object called cachorro and would like to create and store a copy of that object. As objects, vectors, functions and regular expressions are considered objects I cannot make a copy just by…
-
39
votes8
answers48548
viewsHow to pass parameters in function calls by reference in Javascript?
I recently asked the question Why should we use Anonymous functions with jQuery instead of the function directly? and along with the accepted answer came a second question: How to pass arguments to…
-
3
votes8
answers4914
viewsDo not allow saving image of a web page
I don’t want the "save image as.." option to appear when I right-click an image on an HTML page. That is, it will be impossible to save images from the site. How can I do this check?
-
29
votes8
answers95476
viewsHow to check with jQuery if there is a checkbox checked?
I would like to know which Checkbox is checked with Jquery. To catch all the checks I made the following code var checado=false; $(obj).find("input[name='analisar']").each(function(){…
-
79
votes8
answers16873
viewsHow to invert a string in Javascript?
How to invert a string in Javascript? For example: Entree: "something here" Exit: "iuqa asioc amugla"
-
17
votes8
answers45427
viewsHow to disable the scroll of a web page?
I’ve been trying to disable one-page scrolling. All I have found are type solutions: #container{ overflow: hidden; } But that’s just occult scroll bar. How I would disable scrolling, even with it…
-
51
votes8
answers2113
viewsIs using customer validation enough?
Using Javascript validations is sufficient for efficient validation? Example: Date validation. It is necessary to check also in the code? What are the disadvantages of only performing validations…
-
4
votes8
answers481
viewsI can’t learn syntax for
I can learn subjectively for a few seconds, but I can’t fix it no matter how hard I try. I’ve already repeated classes, I’ve done exercises and everything, but the syntax and its variations just…
-
17
votes8
answers34672
viewsConvert every first letter of every word into uppercase
I have the following question: Write a titleize(text) function that converts every first letter of every word into uppercase. ex: titleize("this IS just A Text"); // correct output -> (This Is…
javascriptasked 10 years, 4 months ago David Bastos 355 -
9
votes8
answers794
viewsMapping an array with possible subarrays as elements
I am trying to create a function that files an array to another newArray. If one of the array elements is an array, I want to map all its subelements to newArray. Therefore: var array = [1,2,3,4,5,…
-
7
votes8
answers955
viewssplit/regex only on the first vertical bar "|"
I want to share the string in 2 parts (will always be a array divide into two parts - or two elements) each time a vertical bar | (only in the first case). For example: I have a string var string =…
-
5
votes8
answers3758
viewsExercise taking the position of the array
I’m doing an exercise but I can’t go through all the necessary validations. Write the function "medalText(number)", which takes a number as a parameter, using only an "if". You have to return the…
-
32
votes7
answers58283
viewsRegular expression for e-mail validation
I am trying to create a regular expression to validate any e-mail, I wrote the expression below, but it is not working as expected: var parse_email = /^[a-z0-9.]+@[a-z0-9]+\.[a-z]+\.([a-z]+)?$/i;…
-
9
votes7
answers31206
viewsHow to insert data into DB with jQuery/Javascript without using PHP?
I am learning Javascript and jQuery and I am wanting to make a small site to test the insertion of data in a database. I have no knowledge in PHP, I wonder if it is possible to insert data in a…
-
66
votes7
answers12436
viewsUse semicolon or not at the end of the lines in Javascript?
I have read some comments on the web about whether or not to use the ; at the end of the lines when writing Javascript. Some say yes, others say no need, but none can explain well the reasons for…
-
9
votes7
answers16282
viewsUnderstanding the JSON file
I have a code similar to this on Jsfiddle. On my home WAMP server I did to try working with JSON (Jsfiddle does not contain the JSON file to test). In a question I asked about how to insert data…
-
18
votes7
answers44529
viewsHow to get only the numbers of a string in Javascript?
I wonder if there are functions that return only the numeric values of a string, if there is not, what is the simplest and efficient way to implement? Example: apenasNumeros("5tr1ng"); Upshot: 51…
-
20
votes7
answers43303
viewsHow do I know if a variable is of the Javascript Number type?
In javascript, because there is no declaration of the types of variables such as Integer, String, Boolean, etc., it is a difficult task to know what kind of value you are dealing with in a given…
-
117
votes7
answers78990
viewsHow does this if/Else work with "?" and ":"?
I am studying Javascript and I have doubts about the different ways to make a if/ else. For example, this: foo ? foo : foo How exactly does it work?…
-
10
votes7
answers39327
viewsHow to create input masks with Javascript?
I need to create a mask for a Javascript-only phone input (I can’t use jQuery). How can I do it?
javascriptasked 10 years, 11 months ago user3388 -
11
votes7
answers3042
viewsHide input value
I need to hide/remove the value from my input, but I’m not getting it at all, where am I missing? Thank you very much HTML: <div class="caixa-pesquisa"> <div…
-
8
votes7
answers3980
viewsHow to check if there are numbers inside an input with Javascript?
Form validation with Javascript is something routine in web development, but always cause headaches! My situation is as follows: I cannot allow numbers to enter a 'name' field, but how can I do…
javascriptasked 10 years, 10 months ago valdiney frança 387 -
7
votes7
answers6999
viewsSplit() integer with Javascript
Valor = 19.90; MyArray = valor.split("."); the code hangs , whole variable, however if, Valor = "19.90"; MyArray = valor.split("."); alert(MyArray[0]) = 19; alert(MyArray[1]) = 90; I would like to…
-
111
votes7
answers13788
viewsHow to represent money in Javascript?
What is the best way to represent monetary units (i.e. money) in Javascript? I know it is not good to use floating point, given the rounding problem, but I do not know what would be the best…
-
34
votes7
answers87300
viewsHow to validate with regex a string containing only letters, whitespace and accented letters?
I’m looking to validate one input text for full name in order to accept only letters, blank spaces and accented letters. Valid formats: Leandro Moreira leandro moreira Kézia Maria kezia maria Cabaço…
-
30
votes7
answers46159
viewsRemove repeated elements within a Javascript array
How to remove repeated elements within a Javascript array? I have for example: var array = ['foo', 'bar', 'foo']; And I want to remove all duplicates to get: ['foo', 'bar']…
javascriptasked 10 years, 7 months ago user8789 301 -
29
votes7
answers53067
viewsKnowing if the number is odd or even
I wonder why nothing happens to my code. Even the variable n the alert appears, but then nothing else happens. var n = prompt("Digite um numero"); var total=n/2; if(n/2=0){ alert("Par"); }…
javascriptasked 9 years, 8 months ago larissa castro alves 293 -
9
votes7
answers4205
viewsCount elements on the screen
I wonder if there is the possibility of me counting the elements on the screen, for example a function that lists the amount of <li> arranged on my website. How could I do that? And how would…
-
5
votes7
answers2833
viewsHow to check if at least one item of the array has value equal to or greater than 2
I have the following array: array[0,2,0,0]; I need to create a function that returns me true if at least one array item has value equal to or greater than 2
-
5
votes7
answers5040
viewsRegular expression for accepting numbers and letters, regardless of sequence
I have the following problem, I need to validate a password field with at least 8 characters, being at least 2 numbers and the rest letters, they can be in any position. 12abcdef abcdef12 The…
-
0
votes7
answers4789
viewsForce input with a dot instead of an html comma
In the table the price field has the Decimal data type, where the input is this way: <p><h5><strong>Preço</strong></h5> <input type="text" id="Preco" name="Preco"…
-
9
votes7
answers1322
viewsPush element from one array to another array
function that accepts a parameter and is a numerical matrix and will cross the array and if the element is even will push to the an array "even" and if it is odd will push to the array "odd" I tried…
javascriptasked 6 years, 4 months ago Isa 1,103 -
2
votes7
answers7167
viewsHow to receive the CPF number and format to be without the dots and dash(Input Mask )
I’m creating a mask with inputMask, but the number is received so: 222.222.488-19. And I want him to have the mask on input but when sending it will be without the dots and the dash. Like this…
-
23
votes7
answers620
viewsHow to access a circular array?
Whereas I have a array: const a = ['A', 'B', 'C']; I would like to create a function that returns an item and, with each call, returns the subsequent one, and when it comes to the end, returns the…
-
2
votes7
answers4295
viewsWhat does it mean Does the solution make comparisons against strings in the following code? JS
The statement of the financial year is: Declare the dayFew you receive a "Sunday" string. Then implement a conditional using if that compares diaDemana is equal to "Sunday", if true print a string…
-
22
votes6
answers34688
viewsHow to send emails only with HTML5 basics
I am building a website to be hosted on a server that does not support PHP or other server-side language. I need to send the values of a contact form by email and my resources are only HTML5 and…
-
23
votes6
answers28585
viewsHow to get Timestamp in Javascript?
I’d like to know how I do in JavaScript to obtain the Timestamp? A number that represents the current date and time. I know we got the object for date and time through: var d = new Date(); But I…
-
21
votes6
answers18042
viewsHow to make a Custom Scrollbar?
How to modify a scrollbar div, to appear as in the image example below (Hangouts), instead of the standard operating system scrollbar?…
-
89
votes6
answers9431
viewsWhen should var be used in Javascript?
I’m always in doubt in the projects I put var before giving a value to a variable or not because both work (I think). Can anyone explain why they use it or not? What convention or good practice to…
javascriptasked 10 years, 11 months ago Joao Paulo 11,760 -
66
votes6
answers27772
viewsWhen, why and how to use the "use Strict" directive in Javascript?
I had never seen before the use of this directive, but almost all the most mature jQuery plugins use it. I would like to know when and how to use it and what its purpose is.