First I have this.
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="varenummer" id="varenummer" onkeyup="gethint(this.value)" hidden=true style="display:none">
</form>
And then later on I have this
if (isset($_POST['tryk'])) {
$pri = mysql_real_escape_string($_POST['pri']);
$sek = mysql_real_escape_string($_POST['sek']);
$dat1 = mysql_real_escape_string($_POST['dat1']);
$dat2 = mysql_real_escape_string($_POST['dat2']);
$dat3 = mysql_real_escape_string($_POST['dat3']);
$dato = $dat1 . "-" . $dat2 . "-" . $dat3;
$tek = mysql_real_escape_string($_POST['tek']);
$id1 = mysql_real_escape_string($_POST['id1']);
$varenummer = mysql_real_escape_string($_POST['varenummer']);
$insert = mysql_query("insert into Servicetxt (ID2, Servicenum, PriServiceTxt,
SekServiceTxt, Teknikker, Dato, Varenum) VALUES ('NULL', '$id1', '$pri', '$sek', '$tek',
'$dato', '$varenummer')")or die(mysql_error());
}
The thing is, the submit-button ‘tryk’ is placed on an ajax page. How can I save the value of the textbox(varenummer) as a php-variable before the isset($_POST[‘tryk’]), without pushing any button?
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
SESSIONhere is sample code.
Js Code
PHP Code
And the you can use that session variable globally as
$_SESSIONis SUPER-GLOBAL itself.