Pass a value from a script to php

0

I have the following function:

function distribucion_referencia(value)
    {

             var pago_total=cantidad_pagar_total.value;
             alert(pago_total/value);
             var pago_fracción = "" + (pago_total/value);
             $("#cantidad_rb_1").text(pago_fracción);
     ...}

The amount found in pago_fracción I want to print it in a input as a monetary amount, only I can not pass that data to PHP .

    
asked by cesar 08.09.2017 в 19:32
source

1 answer

0

What you must do is to pass the JavaScript to an HTML input and HTML to PHP using a form. Here is an example:

<?php 
 $valor = $_POST['valor']; //Recibes el valor del input mediante su nombre.
 ?>

 <form method="post">
    <input type="number" name="valor" id="valor"> <!-- Input donde setearás el valor -->
    <input type="submit" name="enviar" value="Enviar">
 </form>

 <script type="text/javascript">
    function darvalor (){ //La función debes iniciarla en alguna parte.
        var valor = 1;
        document.getElementById('valor').value = valor ; //Con este código debes buscar el input por su id y seguidamente setearle su valor.
    }
 </script>
    
answered by 08.09.2017 в 19:43