Posts by BrTkCa • 11,094 points
375 posts
-
3
votes1
answer232
viewsA: Identify a long click with jquery
Or you can use the event taphold jQuery Mobile API: The jQuery Mobile taphold event kicks off after a ringtone event complete and sustained (also known as long pressure). In your case I’d be more or…
-
1
votes2
answers475
viewsA: Input alert if typed data is invalid
Another way is by using the attribute Pattern of HTML. HTML: <form> <label for="choose">Qual seu telefone?</label> <input id="choose" name="i_like"…
-
2
votes1
answer60
viewsA: PHP and Javascript - Hosting and opening files in formats other than PDF
With Javascript, you can get the file type and check if it has the PDF or JPEG type using files[0].type at the event change of input : document.getElementById("arquivo").addEventListener("change",…
-
1
votes2
answers115
viewsA: Ajax search inside jquery div clone
When you clone it is understandable to repeat the idin your case. Try to make the selection by any property: HTML <input type="text" autocomplete="off" id="produto" produto name="produto[]">…
-
4
votes3
answers112
viewsA: DOM search for positive name and value
Syntax is wrong, to use multiples attributes is that way: $('input[name="FLG_SEXOX_CLIEN"][value="valor_aqui"]');…
-
6
votes1
answer512
viewsA: Doubt on how to change jquery Mask type
You can check in the condition change jQuery, and change the mask: $('.valor').mask('00.000.000,00', { reverse: true }); $("[name=categoria]").change(function() { if ($(this).val() == '1') {…
-
2
votes2
answers56
viewsA: Is there a way to transform a string as a path?
As you are sending a string, just switch to the selection mode to: sql.datatypes.integer[type].mysql var sql = { datatypes: { integer: { INT: { mysql: 'INT' }, SMALLINT: { mysql: 'SMALLINT' } } } }…
-
1
votes3
answers2849
viewsA: Grab button id pressed
You can use the function attr jQuery to get the attribute value: $("button").click(function(){ console.log($(this).attr("id")); }); <script…
-
2
votes1
answer404
viewsA: Fill a select with callback $getJson Asp.Net / Jquery
You can iterate the result of cities received in cb, and instead of using html use append to add a option per city. Example (assuming that the return is an array of cities): var cb = ["São…
-
1
votes2
answers948
viewsA: How can I open a modal after a Submit event
One option is to prevent the page from being reloaded using event.preventDefault: $( "#form" ).submit(function( event ) { event.preventDefault(); $( "#dialog" ).show(); });…
-
2
votes1
answer19
viewsA: Save value to an input after inserting them automatically using Javascript
Instead of using multiple variables to fill in the result, you can only fill in one containing the text, and check that the input is valid. Jsfiddle: http://jsfiddle.net/thallysondias/dsqBf/59/…
javascriptanswered BrTkCa 11,094 -
1
votes2
answers1756
viewsA: Receive txt and generate image from text
If the return is a Base64, it is possible to concatenate the string with the src element, using the markings data:image/gif;base64: var base64String =…
-
0
votes3
answers401
viewsA: How do I send a field just by ajax?
You can get the value of the input with jQuery: $("#visualizarAparelhos").submit(function (e) { e.preventDefault(); var idAparelho = $("#IdAparelho").val(); $.ajax({ type: "POST", url:…
-
3
votes1
answer244
viewsA: check if object items are empty
You can browse the values of the object using for..in and save to a counter. If the counter is greater than 2, it means that at least 3 values have been filled in. Example: var obj = { "param1":…
-
6
votes2
answers1169
viewsA: Value-finding function between Javascript variables
There is the function Math.max: function getMaxOfArray(numArray) { return Math.max.apply(null, numArray); } console.log(getMaxOfArray([1,2,3,4,5,6,7,8,10])); In your case it is possible to call the…
-
2
votes2
answers8606
viewsA: What is the difference between the angular foreach and the javascript map function
Actually both functions are from Javasscript. The difference between forEach and map is the functionality. forEach iterates all array values, while the map returns a new array as it has the mapping…
-
2
votes1
answer889
viewsA: Problems with updated jquery
jQuery must be imported before Bootstrap, this may be an error cause in your case. As @leofontes mentioned, apparently you are importing more than once jQuery - this is not good practice. Your head…
-
1
votes3
answers87
viewsA: How to make animation to show the rest of the paragraph?
Based on the example of CSS Tricks, another way is to delimit the size of the paragraph that will be displayed, leaving a gradient color at the end of it to give the feel of descent in read-more.…
-
2
votes2
answers1519
viewsA: Subtract date with javascript
If the date you have is in this format 17/05/1995 10:45, you can separate by space and pick up only the date: var somenteData = "17/05/1995 10:45".split(" ")[0]; // 17/05/1995 10:45 > 17/05/1995…
-
1
votes1
answer793
viewsA: JS - display elements on the screen from an object
Assuming your object has this structure, you can assemble the components and include them in a div using innerHTML: var obj = { "perguntas": [{ "campanhaId": 1, "id": 1, "nome": "pergunta 1",…
-
10
votes3
answers4398
viewsA: Difference between Promise and callback
Promise represents a promise of a future outcome of an asynchronous operation. And Promises can be understood as asynchronous callbacks. One of the advantages I know is using Promise.. Returns a…
-
1
votes1
answer105
viewsA: How to get the video size from the path?
If you want to get the video size and are using the same function as your another question, you can get by attribute size which is returned in bytes. Then to convert in MB: var tamanho =…
javascriptanswered BrTkCa 11,094 -
2
votes1
answer156
viewsA: How to select Option value with Ajax data return?
In the selector I believe you should include options and check if the attribute value data-tokens is the same as returned by ajax: $('#priorities-info option').each(function() { if (…
-
2
votes4
answers353
viewsA: use F2 to click on jquery button
You can identify the event click on the body and if it is F2 click on the button. $('body').keypress(function(e) { var code = e.keyCode || e.which; if (code == 113) { // 113 = f2 $('#btn').click();…
-
0
votes5
answers3128
viewsA: What is CDN and how do I enable it in my Javascript files?
Content Delivery Network (CDN or Content Delivery Network), are servers that provide content. Usually, to implement it, is to insert an external source to the project. Example: Local <script…
-
2
votes3
answers222
viewsA: Check if there are equal fields in a form
You could check the value of each option and disable those that have the same value, so the user could only add different options: $("form > select").change(function() { $("form > select >…
-
3
votes2
answers637
viewsA: Time difference between Javascript and Mysql dates
Javascript entente data in millisecond format. The way you thought about doing it might work, convert the data_inicio in Mili. But I think that converting from milliseconds to date is easier. To…
-
1
votes3
answers1314
viewsA: How to read a . json file in the Angular module.config()?
Javascript does not have direct access to the disk, that is to say that there is no function that directly accesses any file, as the fs.readFile of Node.js or Java File Reader. I suggest two…
-
1
votes3
answers512
viewsA: Add option inside optgroup
With javascript you can add HTML elements using element.innerHTML. In your example, it could be something like: // obtem o segundo optgroup pela label var opt =…
javascriptanswered BrTkCa 11,094 -
1
votes2
answers7745
viewsA: How to check if an element has a class, or is with an "active" class
With javascript it is possible to get the classes using element classname., where a string is returned with the classes of the element, and check the existence of some with indexef. var classes =…
-
1
votes1
answer685
viewsA: How to upload images only after clicking button
One way is to leave display: none of the items that will be hidden and when you click on the button display them. $(".botao").click(function(){ $("li[esconder]").show(); }); li[esconder] { display:…
-
3
votes2
answers366
viewsA: Remove Focus from input when it is with attr readonly
You can use disabled="true", and when removing readonly also enable input. <input type="text" disabled="true" readonly="readonly" onblur="alert('teste')"> Or check if it is as readonly in Blur…
-
0
votes2
answers194
viewsA: Hello Word javascript
Another option is to put the code in the onload: window.onload = function(){ var myHeading = document.querySelector('h1'); myHeading.textContent = 'Hello world!'; }…
-
2
votes1
answer122
viewsA: Convert String from a div to int and do a mathematical operation
Nan is an error returned to non-numeric (not a number). You will have to convert to number using parseFloat: $("button").click(function() { $("#resultado").text(calculaParcela()); }); function…
-
3
votes6
answers906
viewsA: Convert text from div to number
You can use regex. /\d+,\d+/g Where: \d+ = search by numbers , = includes the comma /g = global (across the string) Example: $("button").click(function(){ var regex = /\d+,\d+/g; var texto =…
-
1
votes2
answers2530
viewsA: How to remove all "/" occurrences from a string using Javascript
One option is to break through / and then put together. var str = "/Date(1421287200000-0200)/"; str = str.split("/").join(""); console.log(str);…
-
0
votes3
answers3421
viewsA: Write to files without erasing its contents
One option is to use the class Files. It would look something like: try { Files.write(Paths.get("C:/arquivo.txt"), "NOVO TEXTO".getBytes(), StandardOpenOption.APPEND); } catch (IOException e) {…
-
7
votes5
answers3614
viewsA: Split array into smaller groups
You can use the method Array#Slice that will divide the array based on the start and end index, iterating the array by a cut value, taking into account that its array may have n full size. var…
-
0
votes2
answers696
viewsA: Replace an input value and keep the previous value
In javascript, something manual is to replace the characters by others radorically as the user type and store the original value. Could be more or less like: var textoOriginal = ''; var entrada =…
-
1
votes2
answers1834
viewsA: Select option when clicking button
By clicking a button, you can identify which button is and thus change the status of selected to the respective element option: $("button").click(function(e) { e.preventDefault(); var id =…
-
1
votes4
answers7208
viewsA: How to group an object array in javascript (Angular)
If the object array is too extensive, you can separate an array of nonduplicated objects by mapping the days and months and then filter based on what was discovered. var arrayDeObjetos = [ {"dia":1…
-
2
votes1
answer1277
viewsA: put a load with jQuery on the button
As for the button you could insert an image in by clicking. $(".button").click(function() { $(this).html("<img src='http://cdn-frm-us.wargaming.net/4.5/style_images/wg/ajax_loading.gif' />");…
-
3
votes2
answers1292
viewsA: How to check if HTML tag has given attribute with JS?
Another way is to get the value of src, then check whether it is empty or not: var src1 = document.getElementById("SizeImage1").src , src2 = document.getElementById("SizeImage2").src; // verifica se…
-
3
votes2
answers892
viewsA: Grab Id and move to another function on click button
If you choose to add to the global scope could do something like: <script> var idSel; $(document).on("click", "a", function(){ if ($(this).hasClass("clique")) { idSel = $(this).attr('id');…
-
1
votes2
answers108
viewsA: Taking Dropdown’s Name and ID
To get the values of select you can use: $("#cidade").change(function(){ var idCid = $(this).attr("id") , valor = $(this).val() , nome = $(this).attr("name"); console.log(idCid, nome, valor); });…
javascriptanswered BrTkCa 11,094 -
1
votes3
answers95
viewsA: Load an element in ajax as user chooses
The attribute id should be unique but you can get the entries by name, add a listener (Listener) to each radio button and create a textarea if it is option 1. With pure Javascript can be something…
-
2
votes2
answers260
viewsA: Error sorting positive and negative numbers Jasvascript
You will have to remove the decimal points from all values in the array in order to consider it as an integer. For this you can use the Array#map, within the function by converting each number into…
-
1
votes2
answers531
viewsA: Insert HTML into Link inside Div automatically with jQuery
You can use the attr jQuery: $("#popup-imagem > a").attr("data-popup-open","popup-1"); > a selects the elements a where the father is popup-imagem. His syntax is: .attr( attributeName, value…
-
2
votes4
answers1467
viewsA: Show and hide div
Another way is to use siblings jQuery: $('div.'+div).siblings().hide(); $('div[class="'+ div +'"]').css("display","inline"); function teste(div) { $('div.'+div).siblings().hide(); $('div[class="'+…
-
1
votes4
answers3391
viewsA: Perform Jquery percentage calculation
$("#percent").change(function() { if (parseFloat($(this).val()) <= 100) { var porcentagem = (parseFloat($("#valor").val()) * parseFloat($(this).val())) /…