Recover a value that comes from a jquey to PHP request

Asked

Viewed 95 times

2

I am here with a difficulty, I am receiving a value that comes from a JQUERY request to be presented in a form input, with the code:

HTML

<input type="text" id="valor">

With this TAG I can recover the value I want in HTML, my problem now is how I will pass it to a PHP variable.

I already tried using this method, follow the code:

JAVASCRIPT

var valor = document.getElementById("valor").value;

Next in PHP I try to recover it this way, follow the code:

PHP

$varphp = "<script>document.write(valor)</script>";

But I couldn’t, what can I do to fix the code? Because I need the code that appears in the form input tag to convert to a PHP variable.

1 answer

0

This interaction does not exist (or should not exist).

In this context js is running in the browser and PHP is on the server.

The value of input should be passed to a PHP page via request.

  • It is already passed 1x by means of a form, but as I want to open 2 modal windows I want to recover the data from 1 window, so this <input> already contains the javascript variable I want, my problem now is to be able to convert this value to PHP, I know it’s a weird procedure to do, but what I’m doing is really complex, so I have to cut back somehow, because there are a lot of lines of code that I would have to change!

  • Do you already have the value in your JS? then make another request (maybe AJAX) for another PHP resource.

  • First step is to forget about this idea of yours. PHP Scripts don’t know what JS is.

Browser other questions tagged

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