Posts by Wictor Chaves • 8,445 points
320 posts
-
3
votes4
answers148
viewsA: My functions only return 0
Place the variables within the scope of Submit, so the values will be assigned in Submit, and the Math.sqrt method does not accept negative values, then return Nan (Not a number). var form =…
-
2
votes1
answer80
viewsA: Format the Array view in C#?
Here is the code, and its operation explained in the comments using System; public class Program { public static void Main() { string[] nomes = { "Maria", "João", "Francisco", "José", "Antonio",…
-
1
votes2
answers201
viewsA: What is the difference between the string.Slice() method and the string.substring() method?
slice() works as substring() with some different behaviors. Syntax string.Slice(start, stop); string.substring(start, stop); What they have in common: If start equals stop: returns an empty string…
-
0
votes1
answer232
viewsQ: How to consume an API "without permission"
In the searches I did, I found that it is not possible to consume an API if you do not release your host on the server(back-end), but I hope you are mistaken, this is the reason for this question,…
-
0
votes1
answer114
viewsQ: How do I make pdfkit ignore extensions?
I have the following code import pdfkit options = { 'page-size': 'Letter', 'margin-top': '0.75in', 'margin-right': '0.75in', 'margin-bottom': '0.75in', 'margin-left': '0.75in', 'encoding': "UTF-8",…
-
0
votes1
answer75
viewsA: Set a css class and render the form in Django
I spent about two days chasing after this answer, I did amazing things in my code to try to solve this problem, and in the end find that it is something super simple, just put the following line in…
-
0
votes1
answer75
viewsQ: Set a css class and render the form in Django
I created the following class: from django import forms class FormDefault(forms.Form): def __init__(self, *args, **kwargs): super(FormDefault, self).__init__(*args, **kwargs) for field_name, field…
-
0
votes1
answer183
viewsQ: Explain template location in Django
I’m using Django for a project, but I came across a question. In my file settings.py I have the following configuration of templates: TEMPLATES = [ { 'BACKEND':…
-
1
votes2
answers1106
viewsA: Scroll overlaying the navigation header (navbar) in HTML/CSS
I did it this way: .container{ overflow-y: auto; height: calc(100% - 60px); margin-top: 60px; box-sizing: border-box; } overflow-y: auto; putting the scroll on the y-axis of div container height:…
-
1
votes1
answer81
viewsQ: Strange behavior in Javascript
This question is more out of curiosity, I’ve already answered the problem in my code. I made a money mask using javascript, it was working perfectly, until I entered the value 4.9. Debugging the…
javascriptasked Wictor Chaves 8,445 -
0
votes1
answer182
viewsA: Run php Artisan in a different directory
This will depend on the command you want to run, but let’s assume that you want to run a migration, you can define the path(Way) in this way: php artisan migrate…
-
0
votes1
answer792
viewsA: How to assign the value of a variable in javascript, within php?
You can do it this way: $.ajax({ method: "POST", url: "action.php", data: { x: x } }); Here I am defining the shipping method, the url of the archive php where you will be sent via post the variable…
-
4
votes2
answers60
viewsA: PHP version conflict
The function json_encode only works in php 5.2 or higher, and this way of writing an array using only keys [] only works in php 5.4 or higher. Sources: Arrays json_encode I believe that your version…
phpanswered Wictor Chaves 8,445 -
3
votes1
answer62
viewsA: Pass AJAX data
You can put directly this way: function load_image_data(){ $.ajax({ url:"/fetch.php", method:"POST", data: { token: "<?php echo $tokenAnuncio; ?>" }, success:function(data) {…
-
1
votes1
answer366
viewsQ: How jquery events work
I will show examples only of the click event to be simpler to explain, but this is related to any jquery event. When I started using jquery I only used the click event as follows:…
-
2
votes2
answers441
viewsA: How to create an Operation Confirmation Alert?
You can do it this way: var button = $("button") button.on("click", function(){ var confirmado = confirm('Deseja deletar?'); if(confirmado){ alert('Confirmado!'); }else{ alert('Negado!'); } })…
jqueryanswered Wictor Chaves 8,445 -
3
votes1
answer71
viewsA: How to change color in html
The problem is time to use the quotes, if you want to use inside the quote string you need to put this way ", I removed the font tag that is no longer used, and used style instead: var message =…
-
2
votes1
answer952
viewsA: Redirect p/new page when 404 error occurs using Laravel 5.6
You can create a script inside the page 404.blade.php to make this redirect in this way: <script> window.location = "http://www.yoururl.com"; </script> Or change the file…
-
0
votes3
answers767
viewsA: Escape Single and double quotes from the text area even giving Crlt+V
You can do it as follows, just by checking the quotes and simple quotes with a simple if: $(function(){ $('#bot').keypress(function (e) { var str = String.fromCharCode(!e.charCode ? e.which :…
-
3
votes2
answers577
viewsA: Find html element in css
When you want to use with id or class is simpler Example with id: #textoUm{ color: #FFFFFF; } Example with class: .textoUm{ color: #FFFFFF; } Or if you want something like, an input with class…
-
13
votes2
answers9028
viewsA: Insert character in a specific position
Solution I created a function to make it easier to work and so it can be reused elsewhere. I use the function substr to take from option "0" to the position passed as parameter, in the example in…
phpanswered Wictor Chaves 8,445 -
3
votes2
answers541
viewsA: Cutting strings from right to left
You can do it this way: $codigo = "1804444"; echo intval(substr($codigo, -5)); The substr function removes 18 from the string and then this string is converted to integer by returning in the case of…
-
1
votes2
answers1034
viewsA: How do you pass two parameters in Ng-click Angular JS?
It just separates with a comma, this way: deleteCategory(cat.id, cat.name) Thus remaining: <button class="btn btn-conf-t btn-deletar" ng-click="deleteCategory(cat.id, cat.name)"><i…
-
0
votes2
answers171
viewsA: How do I send the src value of an img tag to the value of a text field?
function teste() { //Você pode colocar outro id em imagem também, já que "imagem" é algo muito generico. var src = $("#imagem").attr("src"); //Você pode colocar um id no seu input, já que…
-
2
votes1
answer151
viewsA: Upload files working with PHP sockets
You can send the files using Base64, see a simple conversion example using php: $image64 = base64_encode('caminho/da_img.jpg'); To decode is very simple too: function base64_to_jpeg($base64_string,…
-
1
votes1
answer551
viewsA: csrf token error in the Laravel
You should put inside your form @csrf. @extends('layouts.app') @section('content') <div class="container"> <h1>Funções do <b>{{$user->name}}</b></h1><br>…
-
1
votes1
answer336
viewsA: Ajax does not receive controller response
In the Laravel so you can send something via post you need to put in the form o @csrf, and when sending using ajax you need to specify it in headers, you can do it this way: $.ajax({ headers: {…
-
2
votes1
answer7637
viewsA: Convert Int to String in C++
You can do it this way: #include <iostream> #include <string> int main() { std::string resultado = " "; int n = 1; char l = 'a'; resultado = resultado + std::to_string(n) + l; std::cout…
c++answered Wictor Chaves 8,445 -
4
votes2
answers98
viewsA: How do you compare a string when it only has one space?
This is simple to solve, just leave only the quotes without the space and put the variables inside the function Trim (denied): if (!trim($nome) or !trim($categoria) or !trim($rua) or !trim($numero)…
-
6
votes5
answers3268
viewsA: Make lamp light on and off
You can do it this way function ligarDesliga(){ var imagem = document.getElementById('lamp').src; var imagem_ligado = 'https://www.w3schools.com/js/pic_bulbon.gif'; var imagem_desligado =…
javascriptanswered Wictor Chaves 8,445 -
0
votes1
answer674
viewsQ: Receive a Long String with esp 01
I have a esp 01(Wi-fi module) connected in my Arduino on port 2 and 3(TX RX), I can send a large String, but when I receive I can only receive at most 32 characters, here is the code of my Arduino:…
-
0
votes1
answer187
viewsA: How to save relationship tables in Laravel?
I decided as follows I imported the following class: use Illuminate\Support\Facades\DB; And I put my code inside transaction: return DB::transaction(function () use ($campos){ return…
-
0
votes1
answer187
viewsQ: How to save relationship tables in Laravel?
I will put a small example to explain my problem. Tables: main itens The two have relationship, one main has several itens. What I’m doing to save: ... $main =…
-
1
votes2
answers88
viewsA: Join 2 arrays
You can do it this way: <?php $pessoas = array(1 => "ERICA GRELLERT", 2 => "IARA BEATRIZ", 3 => "DANIELLE", 4 => "MARIANA", 5 => "ALESSANDRA", 6 => "EDUARDO", 7 => "DIEGO", 8…
-
2
votes3
answers957
viewsA: How to set default value in a form through javascript?
You can do it this way: <input type="text" value="" id="codigo" > <script> document.getElementById("codigo").value = "Meu código"; </script> It takes the element using…
javascriptanswered Wictor Chaves 8,445 -
1
votes1
answer746
viewsA: Invalid argument supplied for foreach() - Array
Warning: Invalid argument supplied for foreach() in D: xampp htdocs api consumir index.php on line 7 This message occurs because the variable $itens is not an array, or a possible object to be used…
-
1
votes1
answer74
viewsA: Retrieve gateway from the network?
Has a class called DhcpInfo within the package android.net, it has some variables with network parameters. But the problem that these values should be converted. Image to describe the scenario: Java…
-
8
votes3
answers5888
viewsA: Difference between the create and Fill method - Standard
The two methods do the same things, with only one difference: If you already have a model instance, you may use the Fill method to populate it with an array of Attributes: $flight->fill(['name'…
-
4
votes1
answer137
viewsA: Difference between Run App (Run App) and Apply changes (Apply changes)
Apply Changes: Sends only the changed part of the code, and does not create a new APK and in some cases restarts some activity. Run App: In this case it restarts the application, updates the…
android-studioanswered Wictor Chaves 8,445 -
3
votes2
answers1611
viewsA: Word count using dictionary
Solution I put a counting that is always initialized with 1, so it checks if the word already exists in the dictionary, if true, takes the number of the string, converts to integer and then assigns…
pythonanswered Wictor Chaves 8,445 -
0
votes1
answer789
viewsA: Pick up dynamically created element
I made a small example to better exemplify, this way the event works normally: let x = document.querySelector('#resposta'); x.innerHTML = '<a href="#" data-value="1" class="descricao-resposta"…
-
4
votes5
answers223
viewsA: Sum of hours greater than 24 hours
You can do this with this function: AddPlayTime($times); An example: $times = array(); $times[] = "18:00"; $times[] = "8:00"; echo AddPlayTime($times); function AddPlayTime($times) { $minutes = 0;…
-
2
votes1
answer723
viewsA: PHP - directory path
You can do it this way: $raiz = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR; include $raiz . "news.php"; So you always take the site host and don’t need to worry on which page is called the…
-
2
votes4
answers7998
viewsA: Add and remove classes by clicking Jquery
You can do it this way Html <ul> <li> <a class="active">Opção 1</a> </li> <li> <a class="">Opção 2</a> </li> </ul> <div class="content…
jqueryanswered Wictor Chaves 8,445 -
2
votes1
answer37
viewsA: $_POST not returning correctly
Your code is this way, so by clicking submit it simply goes to another page and send the fields via post: <form action="action_page.php" method="post"> First name: <input type="text"…
-
0
votes1
answer18
viewsA: Doubt About Eclipse
Click the arrow at the top of the "package explorer" window and click on "1 Empty Parent Packages". Source: https://stackoverflow.com/questions/20142470/eclipsedefault-package-always-visible…
spring-tools-suiteanswered Wictor Chaves 8,445 -
3
votes3
answers96
viewsA: Compare inputs with the same class and no id
You can do this way, the same html: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <table> <tr> <th>Valor1</th>…
-
1
votes2
answers221
viewsA: Turn decimal into Vb minutes
You can take the decimal part of the number this way: parte_decimal = (valor - Int(valor)) So you subtract the whole part, leaving only the decimal part.
vb.netanswered Wictor Chaves 8,445 -
2
votes1
answer106
viewsA: Field validation
You can do the check this way: if (string.IsNullOrWhiteSpace(MaterialTextBox.Text)) { // Mensagem para o usuário return false; } Using your own code: if…
-
1
votes4
answers1182
viewsA: Change placeholder by checking radio with jquery
First of all you can’t put the same id for two different elements, so I removed it from the element radio, and used the name to manipulate. I added the event change, to be able to take the change of…