Posts by Sam • 79,597 points
3,121 posts
-
0
votes3
answers86
viewsA: How to position the Text of a span below a Spinner
Apply the following properties to #cover-spin: text-align: center; ALINHA O TEXTO AO CENTRO HORIZONTALMENTE line-height: 100vh; ALINHA O TEXTO AO CENTRO VERTICALMENTE padding-top: 60px; MOVE O TEXTO…
-
2
votes1
answer1457
viewsA: How to get form values before Submit with jQuery?
Using .serializeArray() you will create an array of objects where each object will have two pairs of values: [{ "name": "nome do elemento", "value": "valor do elemento", }] For example, if I have…
-
1
votes2
answers152
viewsA: How to make a text field mandatory when one of the radio Buttons is selected?
The id Empresa does not exist, he is a value. So you can check by value radio: $('input[name="Tipo"]').change(function () { if(this.value == "Empresa") { $('#Idsiliamb').attr('required', true); }…
-
0
votes1
answer126
viewsA: Take effect Parallax cell phone
You can use a media Rule to disable the fixed background (background-attachment: fixed) at resolutions up to 1024px. Put at the end of your CSS: @media all and (max-width: 1024px) {…
-
0
votes1
answer85
viewsA: Fields to be filled in automatically
Instead of using Javascript methods, use the .on() jQuery on events. For example, instead of using: var bairro = document.querySelector('#bairro'); var paragrafobairro =…
-
1
votes2
answers367
viewsA: Sort an array in Javascript
Then you have to use a function by comparing the items according to the value of the position of the letters in the string you ordered. Using .indexOf() you find the position of the first letter in…
-
1
votes1
answer79
viewsA: Revert animation in second click
This functionality of .toogle in switching two functions has already been removed since version 1.9. The method is used to animate hide/display elements. I suggest you don’t use .animate for this:…
-
2
votes1
answer123
viewsA: Colors of names in a Javascript chat
The problem is that you are generating new colors for those that already exist in the first loop for (where you have the variable i) of function montarTabela(). With this, each time you assemble the…
-
2
votes1
answer51
viewsA: How to create an email resend after 30 days?
To return only the records where the column DATA (assuming the column is of the date or datetime) has a date equal to or earlier than 30 days from the current date, you should use the operator <=…
-
4
votes5
answers9207
viewsA: Change the color of the text by clicking a button
You can use the method .classList.add('nome da classe') which will add the class .alterar to the selected element when the button is clicked. You can place the code inside an attribute onclick:…
-
1
votes1
answer38
viewsA: Fetch ID value using preg_match_all in PHP
You can use the class Domdocument (PHP 5+) and work with the string as HTML, making it easier to manipulate the elements as HTML, and use a loop foreach us spans picking up the attributes id and use…
-
1
votes1
answer263
views -
2
votes2
answers53
viewsA: Implement "loading..." message display in Javascript
Post the message before AJAX ($.ajax({...})) with the same innerHTML, but you can use jQuery for that: $(function(){ $('#feed_msg').submit(function(event){ event.preventDefault(); var formDados =…
javascriptanswered Sam 79,597 -
1
votes3
answers84
viewsA: Prevent link from opening while clicking and holding to drag in Google Chrome
There is an alternative using two events: mousedown and mouseup. When the user clicks on the link and holds for more than 100ms, it will change the variable flag for true, and when releasing, firing…
javascriptanswered Sam 79,597 -
0
votes1
answer51
viewsA: Delete key if all values are empty
Make two loops, like you did, but create a separate array by adding the names of empty keys to all objects. Then make two more loops by deleting the key names that were saved in the array. const…
-
0
votes1
answer157
viewsA: Fill the src attribute of an iframe and make it visible via jQuery when user click item
You need to add one event.preventDefault() click event to prevent the link redirect or reload the page. The rest of the code seems normal to me: $(document).ready(function(){…
-
1
votes1
answer246
viewsA: Loop with For Next in classic ASP
Do so: <% for data = year(now) to year(now)+10 response.write data &"<br>" next %> The year(now) take the current year. The code above will print: 2019 2020 2021 2022 2023 2024 2025…
-
1
votes3
answers601
viewsA: Is a Switch within an Else possible?
Really use a switch find unnecessary in this case. You can make a sequence of if else and finally a else (when none of the conditions of if else have been met). You can even simplify the code by…
-
2
votes1
answer67
viewsA: Interrupt setInterval for a function to run in its place?
This is what @fernandosavio said. setInterval() needs an identifier, for example: timer = setInterval(function(){ //executa ações }, 1000); To stop it, use the identifier assigned to the…
-
0
votes2
answers123
viewsA: How to know percentage of animation in CSS
Using Javascript (jQuery) it is possible to calculate the percentage of the animation using the events animationstart (when initiating) and animationend (when it ends), and anywhere in the animation…
-
2
votes1
answer58
viewsA: Add values in the array from a JSON that has the value of a variable
What you need to do is a .push() (add values in the array). As you are doing, you are creating and overwriting the positions [1], [2] and [3] of the array, and at the end of the loop only the last…
-
4
votes3
answers592
viewsA: Adapt formatting of input
You can use the attribute pattern and required (both HTML5). The required will prevent the submission of the form if nothing is entered in the field, and the pattern will prevent sending the form if…
-
2
votes1
answer263
viewsA: Fill in input with the day of the week according to the date in the previous input
You can use an event change in the date input and insert the day of the week in the other input whenever you change it. But you must use the object Date() to extract the day of the week from the…
-
2
votes2
answers234
viewsA: Margin-top does not push div down
Can change the margin: 0 auto; for margin: 30px auto 0 auto;. When the margin has only 2 values, the first is the top and bottom and the second of right and left. Making the exchange for margin:…
-
2
votes2
answers333
viewsA: How do I get a "spin" in CSS using the border of a div?
You can use spans along with the icon fingerprint. Then just work with one keyframes to make the animation by rotating two spans in sequence: the one on the right starts the animation immediately by…
-
1
votes1
answer55
viewsA: Datepicker - Add events to datesDisabled
Assign the events click and mouseover to class .disabled-date, which is the class of dates listed in the option array datesDisabled:: $(function(){ $(document).on("click mouseover",…
-
1
votes2
answers140
viewsA: Calculate output per hour using HTML5 and PHP
Do not use type="datetime" which is obsolete (Chrome itself is not supports more). Use type="datetime-local". Use the class DateTime() in the values sent and take the difference with diff(). In the…
-
3
votes2
answers129
viewsQ: Logic to check month with Regex
I’m trying to verify the months that have 31 days with .test() but when the value for the month is 10 (concerning november, which has 30 days - remembering that in Javascript the months are indexed…
-
3
votes1
answer111
viewsA: Return value with PHP and AJAX
Missing you send the value of the element in AJAX by data:: data: {teste: $("#teste").val()}, You also don’t need async: true because AJAX is already async. Missed closing the .done() also with });:…
-
1
votes1
answer99
viewsA: Problem with comparing two cards in a memory game - JS/Jquery
Out of the question of comparison, I noticed 1 error and 2 warnings in your code: The error here is you should call the function with (), who will return true or false: function checkPattern() {…
-
1
votes1
answer69
viewsA: Scrollspy set size
You can force with jQuery so that the scrollspy div has the same height as the menu: $(function(){ $('["data-spy=scroll"]').css("height", $("ul.nav-pills").outerHeight()+"px"); }); In the example…
-
1
votes1
answer1113
viewsA: How to change the CSS of Datepicker?
jQuery has a page where you can assemble the theme you want for the component (choosing colors etc.) The link is this: http://jqueryui.com/themeroller/ As you want to change only Datepicker, just…
-
1
votes1
answer178
viewsA: Repeat rows from a table using Javascript
I think you’re making an unnecessary mix of JS and jQuery methods. Since you are using jQuery, you do not need to create nodes, just insert a string template using the values .append(). Now, to…
-
3
votes3
answers850
viewsA: Taking value from an input
It does not need id’s. Excessive use of id’s is common for those who do not have broader knowledge of the methods provided by the framework. Inflates HTML and lets bad code work and maintain. Since…
-
2
votes2
answers56
viewsA: Show div containing search content
You can use the selector :contains. It will fetch only the elements that have the text typed in the input. Like :contains is case sensitive (case difference), you can change the behavior of the…
-
1
votes1
answer43
viewsA: How do I run the animation every time I click the same button?
You can use a single function to do this by switching the variable value verify in true and false, using a if..else. In your code, the function play is anonymous and will not be called on…
javascriptanswered Sam 79,597 -
1
votes1
answer51
viewsA: I cannot delete the correct image by passing id through jQuery via Modal
It is because you are repeating the id’s and your code will always get the first one. An id should be unique on the page. You can solve this by converting id’s into classes: <div class="modal…
-
1
votes1
answer136
viewsA: Problem with events and functions running multiple times in jQuery code?
Within the function function inserirFormulario(dados) you are creating Event handlers. This function is called at least twice: Here: $('#formulario-consulta').submit(function(e) {…
-
13
votes2
answers136
viewsA: Improve code jQuery
Since the two elements use the same event, you can group the two in the same selector, and use a ternary to change the values by checking with $(this) which element triggered the event and whether…
-
0
votes1
answer194
viewsA: JS Multi-parameter function that returns an HTML
Create an object with all strings (image and text names) separated by section and numbered, in this way: var dados = { imagens: { 1: "enh_tree_ambidexterity.jpg", 2: "enh_tree_ambideity2.jpg" },…
-
0
votes1
answer257
viewsA: Event keypress and filter data after inserting value into any form input
Use the Event Handler out of function when the page is fully loaded. For this I put document.onreadystatechange with the condition complete. In the value placed .trim() not to fire the .submit() if…
-
3
votes1
answer146
viewsA: I want to pick up multiple checkbox with item ids for AJAX in select all
That one data['checkbox_items[]'] does not exist. You should do the .push() in the checkbox_items which is an array. You do not need to use array in this case name. They don’t really need name the…
-
1
votes3
answers110
viewsA: Take an object from within an array and send it to another array?
Use .push() and .splice() after generating a random number up to the size of the main array: var cartasNaMao = []; var todasAsCartas =[ { id: 1, valor: 2, naipe: 'Paus' }, { id: 2, valor: 2, naipe:…
-
0
votes1
answer78
viewsA: Insert new fields dynamically, one next to the other
It’s because you’re not inserting inside a div.row. The class .row will group Divs next to each other, as with Divs within the first div.row that you put. You can resolve by placing the id’s on…
-
0
votes2
answers59
viewsA: Help me work this code
How are 3 possible conditions: Equal number, larger number, and smaller number You could use just one if (equal), else if (major) and else (minor). This is because if none of the first two…
javascriptanswered Sam 79,597 -
1
votes2
answers69
viewsA: Fix last element of the list unordered in footer
What you need to "fix" is the last <li> of the list, not the last <a>. That’s because the <a> is the son of <li> and is not exactly on the list. You should also apply the…
-
2
votes1
answer46
viewsA: Make another div text disappear
If I understand correctly, just create another span with a id within the div#textos2 and hide her in onclick and show on onmouseout: .descricao{ display: none; } <div id="textos1"> <span…
-
0
votes2
answers50
views -
1
votes1
answer806
viewsA: Javascript transition with css
As you are doing in a more beginner way, I will show you a way without messing around too much in your code, which could be better. Create another function where the transition will be made. In CSS…
-
2
votes1
answer242
viewsA: How to enter checkbox validation logic and display message if not selected
You are not using checkboxes, and yes radio Buttons. There are several structural and logic problems in the code. The most serious is that you are using the div#teste to replace the message "Select…