Pass an id "value" to an input field

Asked

Viewed 211 times

0

I use the following Function:

public function autoCompleteCilindro($q){

    $this->db->select('*');
    $this->db->limit(5);
    $this->db->like('passo', $q);
    $query = $this->db->get('cilindros');
    if($query->num_rows() > 0){
        foreach ($query->result_array() as $row){
            $row_set[] = array('label'=>'Impressora: '.$row['impressora'].'    |    Cilindro: '.$row['engrenagens'].'    |    Passo: '.$row['passo'].'    |    Quantidade: '.$row['quantidade'],'quantidade'=>$row['quantidade'],'id'=>$row['idCilindro'],'engrenagens'=>$row['engrenagens']);
        }
        echo json_encode($row_set);
    }
}

I type the approximate value of a step, 200 for example and I am presented the fields of the table "cylinders".

This I do in an input field.

I need to pass to the "height" field the result of dividing the "step" field divided by the "quantity field.

                                    <div class="span6" style="margin-left: 0">
                                        <label for="impressora">Impressora  |  Engrenagem  |  Passo  |  Quantidade de Cilindros<span class="required"></span></label>
                                        <input name="impressora" id="impressora" class="span12" type="text" value="" />
                                    </div>


                                    <div class="span3">
                                        <label for="altura">Altura</label>
                                        <input name="altura"  id="altura" readonly class="span12" type="text" value="" />

                                    </div>

                                    <div class="span3">
                                        <label for="quantidade">Quantidade</label>
                                        <input name="quantidade" id="quantidade" class="span12" type="text"  value="" />
                                    </div>
  • This will be done by Ajax?

  • I believe so, yes. Within a Models file structure, it has a file that has the two public Function funtions add and public Function add().

  • "Do you believe"? You are not the developer of the parade? Apparently, Ajax returns a JSON. Just divide one value by the other and play in the desired field.

2 answers

0

-1

function pesquisa(){
		var valorInput = document.getElementById('procura').value;
		$.post('/valida.php',{valor: valorInput},function(data){
			 document.getElementById('resultado').innerHTML = data;
		})
	}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<form>
	<input type="text" id="procura" onkeyup="pesquisa();">
	<button>Pesquisar</button>
</form>
<div id="resultado"></div>

  • Good morning. I’m not an expert yet in PHP. This file "valida.php", I create it? where and for what purpose ? What would be your code ?

  • Yes, you create it in any folder. For example, if it is in the /SITE/VALIDA.PHP folder then you have to put $.post('/site/valida.php',[...], then in the.php validator you take the input value with $_POST['valor'] and do the validations you want. But for you to test you can give echo $_POST['value'] and you will understand

  • and its content ?

  • https://www.w3schools.com/jquery/ajax_post.asp

Browser other questions tagged

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