How to get the input value in real time?

Asked

Viewed 2,334 times

1

I have this input that is hidden and disabled:

<input type="text" disabled="" id="valorMascara" class="oculto" name="valorMascara">

there are two inputs type radio that sends value pro hidden input, I want to take the value of this input in real time and play within a variable in PHP, WITHOUT SUBMITTING, WITHOUT SENDING THE FORM, I WANT TO TAKE IT IN REAL TIME.

  • 1

    There is no way to change PHP variable via client-side.

  • The answers given already give the solution: you will have to spend a request for the server treat the value of the variable and return the response to the browser. Javascript will fill in the field with no need to reload the page. Everything, theoretically, "in real time".

  • Inside the "PHP variable" has no way, PHP runs on the server side and when the page renders PHP has already been loaded and finished. ie there is no more direct interaction. web is this, requests and HTTP responses. As I explained in https://answall.com/a/168915/3635 and https://answall.com/a/102460/3635

2 answers

1

You will need js, it will be something like this:

$('#iddoinput').keyup(function(){

   var text = $(this).val();
   alert(text);
   //Aqui dentro você faz o que quer, manda pra um arquivo php com ajax
   //ou sla, vai depender do que você quer fazer

});

0

You can do it through an AJAX request:

The script you could use on the client side would be:

$('#id-do-input').on('change', function() {
  var $this = $(this);

  $.post('update.php', {
    param: $this.val()
  }, alert('Enviado!'));
});

And on the server side:

<?php

$param = $_POST['param'];

if (! $param) {
  echo 'Nada foi recebido.';
  exit;
}

// Do stuff...

echo 'Dados recebidos!';

Browser other questions tagged

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