Most viewed "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
-
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);…
-
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") }…
-
10
votes2
answers146605
viewsHow to get input using HTML and Javascript
As a beginner in the language 'JS', I would like to know how to simply pick up text from a <form> (without forwarding to another page and without changing the URL) and passing to a function…
-
27
votes4
answers141141
viewsHow to redirect the user to another Javascript/jQuery page?
I would like to know what methods of redirecting exist in Javascript, and also using jQuery, and if possible, I would like to know all of them.
-
54
votes2
answers126902
viewsWhat is the difference between $(Document). ready() and window.onload?
There is a difference between $(document).ready() e window.onload apart from one being Javascript and the other being jQuery? I see both events are triggered as soon as the GIFT (Document Object…
-
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"…
-
8
votes6
answers96354
viewsHow to make an "Alert" in PHP?
I’m making an email form in PHP, and I’m trying to make one alert when the client clicks to send a validation. The validation seems to work because it redirects to the page I want, but does not…
-
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(){…
-
21
votes3
answers90884
viewsAttribute "href" for Javascript links: "#" or "javascript:void(0)"?
Popularly, there are two methods of creating links that perform a function in Javascript, are they: <a href="#" onclick="myFunction();">Executar JavaScript</a> or <a…
-
44
votes5
answers87966
viewsHow to print content inside a HTML div?
I have a page and in it the content I want to print. I created a Javascript command, but this command prints the whole page. Is there any way to print only the contents of a div?…
-
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…
-
82
votes5
answers86551
viewsUpload a file with AJAX
I wonder if there is any simple way to upload files via AJAX + JSON. If there is, what would it be?
-
17
votes1
answer85227
viewsJavascript generating float with multiple decimals
When creating an order calculation system (quantity x value) I realized that in some cases when adding broken values Javascript returns numbers with many other decimal places more than expected.…
-
2
votes1
answer83416
viewsSend a message to Whatsapp via site
I wonder if there is how to send message to Whatsapp through website. Example: The customer is there on the site and there is a field to enter a message and click "send" and I receive the message on…
-
15
votes3
answers83000
viewsFormat currency with mile separator
I have the following code: function numberParaReal(numero){ var formatado = "R$ " + numero.toFixed(2).replace(".",","); return formatado; } function realParaNumber(texto){ var…
javascriptasked 7 years, 11 months ago Nicolas Guilherme 331 -
3
votes3
answers81788
viewsOpen link in new tab without using target="_Blank" embedded in HTML
Setting I am optimizing a page where is displayed about 200 Images (very small does not need paging) partners, these images are wrapped in a tag <a> and all partner websites open in new tab…
-
12
votes4
answers80887
viewsHow to force the opening of a link in another tab and not window?
I have a button (anchor) that needs to be 'hidden', or no text. Its structure is this: <a class="testeimprimir" href="javascript:teste1();" target="_blank">TESTE</a> The Function is…
-
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 8 years ago Lennon S. Bueno 2,182 -
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?…
-
45
votes5
answers76380
viewsHow to pin a "horizontal menu" to the top of the window when scrolling the page?
I have a layout with a horizontal navigation bar at the top of the site, it is with margin-top:100px, when scrolling the page the menu should be fixed at the top of the window but with margin-top:0.…
-
4
votes1
answer74733
viewsProblems with: Uncaught Referenceerror: $ is not defined
There is a doubt in this forum here, but it doesn’t solve my problem. I have includes, including include jquery in the first line because link found this: Because, JS interpreter search for $ before…
-
17
votes3
answers72494
viewsHow can I check if one string contains another in Javascript?
I would like to check if one string contains another, as if it were a method String.contains() but apparently there is no method to do this. Does anyone know a similar method that does the same…
-
177
votes4
answers72185
viewsWhat is a callback?
I see in many codes and even architectures the word callback, I see that it is in Javascript functions. But what is? How is it used? Why? I’d like an example of real use.…
-
17
votes3
answers72012
viewsGlobal variable in Javascript
How to make a global variable in Javascript? I need the variable that was declared in one function to work in another function. Example: Jsfiddle $("#div3").click(function() { var fill = "a"; });…
-
29
votes6
answers66760
views"foreach" in Javascript
By way of example, in PHP we have the function foreach() (English) which allows us to execute a certain code for each element found in a matrix: <?php $arr = array(1, 2, 3, 4, 5, 6); foreach…
-
38
votes4
answers66720
viewsWhat is the correct way to make a regular Javascript substitution for all occurrences found?
What is the correct way to make a regular Javascript substitution for all occurrences found? The way I do these days: var i = 0; while ((i = str.indexOf("_", i)) != -1) { str = str.replace("_", "…
-
21
votes6
answers65532
viewsSum in 2 inputs and appear in real time - Javascript
My question is the following: I have two inputs type text. One person put a number in input 1 and another number in input 2. When the person had just filled in, the result of adding the 2 inputs…
-
9
votes3
answers61753
viewsRemove a specific element from the javascript array
Well I’m needing to remove an element from the array by index, for example: arr = [1,2,3,4,5,6] When removing index element 3: arr = [1,2,3] It is necessary that he remove everything after the…
javascriptasked 9 years, 1 month ago Renan Rodrigues 3,709 -
6
votes4
answers61202
viewsPlacing value in a text box (input)
I want to put a value in a text box. function open_popup(date_today){ document.getElementById('txtstart').value = date_today; } and html input <input type=text required name='txtstart'…
javascriptasked 10 years, 3 months ago akm 3,387 -
3
votes5
answers59481
viewsTake content from within a Div and put in Input value
I have a form, and inside it I have an input, which will have to take what it contains inside a DIV, which in case is only text. The input is like this: <input class='formContato' type='text'…
-
36
votes4
answers58476
viewsIF, ELSE IF, ELSE or IF IF IF. When to use, what’s the difference?
It’s a very basic question, but it intrigues me a lot. See the code below: var bola = "redonda"; if(bola == "comestivel") return comer(); if(bola == "liquida") return beber(); if(bola == "redonda")…
-
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;…
-
1
votes4
answers57975
viewsHow to clear html form fields?
javascript variables that reference each field of my form var checkbox = $('input:checkbox[name^=check]:checked'); var categoriaVeiculo = $("#codCategoriaVeiculo").val(); var descricaoVeiculo =…
-
32
votes2
answers55629
viewsCORS - No 'Access-Control-Allow-Origin' header is present on the requested Resource
Good evening, I’m trying to access a server from my local machine and I’m getting this answer: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost'…
-
20
votes4
answers55577
viewsHow to validate client-side CPF with script?
I’m working with a CPF validation on my controller, but I need to validate when the customer leaves the input of the CPF and then return a message warning when the CPF is incorrect, through a alert…
-
3
votes3
answers55067
viewsScript to go back to the previous updated page?
Well, I wanted something that did that when a person clicked to go to a page they were redirected to the previous page.. But the page updates... Is that I made a small system of comments, when I…
-
4
votes2
answers54475
viewsPlace Javascript function inside onclick
So it’s kind of a silly question, but I really need... has how I put a Javascript function inside a buttom in this example below it calls the function loadDoc(). more I would like to put the…
-
3
votes2
answers53582
viewsAccess to Xmlhttprequest has been blocked by CORS policy
I have two Flask applications running locally on my machine. One is running on port 5000 and the other on port 5050. I need to make a 5000 app call to 5050. But I’m having this problem: Access to…
-
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, 9 months ago larissa castro alves 293 -
16
votes5
answers51834
viewsIn Javascript, how to verify that an object is empty (without jQuery)?
For jQuery, I can tell if a Object is empty as follows: $.isEmptyObject({}); // true $.isEmptyObject(window); // false To find out if a array is empty, we can do the same, but without jQuery would…
-
11
votes2
answers51084
viewsSliding effect on anchor links
I have a page Onepage and the anchor links of the menus when clicked them only "jump" to the screen section further down, but I wanted them to slide smoothly up to the intended anchoring section. I…
-
6
votes1
answer50551
viewsCapturing an element’s id with javascript click
In the Document there are three <div>, all with the event onclick calling a function. By clicking on any of the three, I would like to capture the id of the <div> clicked. How can I…
-
2
votes2
answers50524
viewsHow to enable and disable button from onclick or onchange from select
I’ve done it with the radio button, but I’m having trouble doing it from a select. When selecting any employee, you must enable and when you select that you represent no employee, you will disable…
-
8
votes1
answer50369
viewsHow do I get current Javascript url?
I am using jQuery. How do I get the path from the current and complete URL, I want to assign it to the variable url_atual. $("#id_ativo").change(function(){ $.ajax({ type: "POST", url: url_atual,…
-
61
votes4
answers49363
viewsWhat is console.log?
I see this in some Javascript files: console.log(algumaCoisa); console.log("alguma coisa"); What it’s for and how it works? I’m trying to make a log() customized for a Userscript (see How can I log…
javascriptasked 10 years, 3 months ago brasofilo 6,560 -
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…
-
108
votes4
answers48488
viewsWhere should I put a Javascript code in an HTML document?
Where Javascript code should be placed in an HTML document: in the element <head> or <body>? At the beginning or end of each one? Is there any difference in performance or any other…
-
9
votes4
answers48238
viewsHow to convert a String to Int in Javascript?
HTML5: <!DOCTYPE html> <html> <head> <title>JSTest</title> <meta charset="UTF-8"> <script src="JSource.js"></script> </head> <body>…
-
7
votes6
answers47809
viewsHow to search for a particular object within an array?
I need to know if determined Array has a objeto with a certain value in its index. I tried to use indexOf, but I was unsuccessful. arr = []; arr.push({id: 1, nome: 'Wallace'}); arr.indexOf({id: 1});…
-
8
votes4
answers47574
viewsCapture screen size at time of request
I wonder if there is any way in Javascript to execute methods at the time of the request that the client makes to the server. I have a project where I use several large images in the occupied memory…
javascriptasked 10 years, 11 months ago Pedro Vinícius 1,870