Load data from a field after pressing a button

Asked

Viewed 694 times

0

I need to load data from a table field.

Example: Table (Template), the person is filling out the form and wants to use this template in the Text field, and with this he would click on a button (Load Template) and load this template in the Text input.

  • Your question is too wide yet, have you made any attempt to do this? Have the table structure already done? Do you already have a model of how this would work? We need more details to give you a good answer. To improve your question you can edict-la

  • Yeah, I got it. The form works perfectly, I just can’t think of how to load the template into the input when the user clicks (Load Template), that this template is a ready text only.

  • 2

    I think it would make it easier to answer if you edited the question to include the relevant code snippets of what you already have ready.

1 answer

2

You can solve this with ajax, if you have done the so famous fields select "State X Municipality", follows the same reasoning.

Clicking on the button will trigger an event that will have an ajax that will point to a php file, where you will take the parameter and mount the specific query and return the database data.

// cadastrarPaciente.js
$("#uf").on("change", function(){
    $.get("modulos/pacientes/ajax_listarCidade.php",
        {uf: $("#uf").val()},
            function(dados){
            $("#cod_cidade").empty();
            $("#cod_cidade").append(dados);
    });
});
// ajax_listarCidade.php
$PArray['uf'] = $_REQUEST['uf'];

$sql = "SELECT cod_mun, nome_mun FROM TMunicipio WHERE uf = '{$PArray['uf']}'";
...

Just follow this line of thought.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.