[Solved] Save textbox as variable without submitting [closed]


PHP is the sever-side programming language while JavaScript (jQuery) runs on the client-side.

we can use PHP to write JS, but JS can’t affect PHP (except via AJAX or similar).

What you can do is use SESSION

here is sample code.

Js Code

$("#varenummer").change(function(e)
{
    e.preventDefault();
    var data_posts = $(this).val();

    // Send Ajax request to backend.php
    $.post("/backend.php", {"varenummer": data_posts});
});

PHP Code

<?php
    // do any authentication first, then add POST variable to session
    $_SESSION['varenummer'] = $_POST['varenummer'];
?>

And the you can use that session variable globally as $_SESSION is SUPER-GLOBAL itself.

solved Save textbox as variable without submitting [closed]