How to assign javascript value to php variable without using cookie
try using this demo code
<script>
if (data) {
var a =data;
<?php $abc = "<script>document.write(a)</script>"?>
}
if (!data) {
console.log('no data');
}
</script>
<?php
echo $abc;
?>
How to assign the javascript variable value to php variable
Javascript works on the user's computer, PHP works on your server. In order to send variables from JS to PHP and vice versa, you need communication such as a page load.
Have a look here on what you can do: How to pass JavaScript variables to PHP? or more specifically the first answer (https://stackoverflow.com/a/1917626/1311593)
Assign javascript value to php variable
I guess you can use cookies for it.
1) First add a cookie jquery plugin.
2) Then store that window width in a cookie variable.
3) Access your cookie in PHP like $_COOKIE['variable name'].(http://www.w3schools.com/php/php_cookies.asp)
How do I pass JavaScript variables to PHP?
You cannot pass variable values from the current page JavaScript code to the current page PHP code... PHP code runs at the server side, and it doesn't know anything about what is going on on the client side.
You need to pass variables to PHP code from the HTML form using another mechanism, such as submitting the form using the GET or POST methods.
<DOCTYPE html>
<html>
<head>
<title>My Test Form</title>
</head>
<body>
<form method="POST">
<p>Please, choose the salary id to proceed result:</p>
<p>
<label for="salarieids">SalarieID:</label>
<?php
$query = "SELECT * FROM salarie";
$result = mysql_query($query);
if ($result) :
?>
<select id="salarieids" name="salarieid">
<?php
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="', $row['salaried'], '">', $row['salaried'], '</option>'; //between <option></option> tags you can output something more human-friendly (like $row['name'], if table "salaried" have one)
}
?>
</select>
<?php endif ?>
</p>
<p>
<input type="submit" value="Sumbit my choice"/>
</p>
</form>
<?php if isset($_POST['salaried']) : ?>
<?php
$query = "SELECT * FROM salarie WHERE salarieid = " . $_POST['salarieid'];
$result = mysql_query($query);
if ($result) :
?>
<table>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td>', $row['salaried'], '</td><td>', $row['bla-bla-bla'], '</td>' ...; // and others
echo '</tr>';
}
?>
</table>
<?php endif?>
<?php endif ?>
</body>
</html>
How to assign php variable in JavaScript value assign?
You simply cannot do that, you need to understand the difference between client/server side programming, you cannot assign Javascript value to PHP variable, yea but you can assign PHP value to your javascript
Twig how to assign a JS variable to PHP variable
It seems Twig does not allow such a thing: https://craftcms.stackexchange.com/questions/21742/local-storage-in-twig
How to assign php variable value into javascript variable
echo
it. But Remember to follow the sequence of definition -
<?php
$name= "Rama";
?>
<script type="text/javascript">
var jvalue = 'Hi, <?php echo $name; ?>';
</script>
<?php
$abc = "<script>document.write(jvalue)</script>";
echo $abc;
?>
Related Topics
How to Submit 2 Forms in One Page with a Single Submit Button
How to Focus on a Form Input Text Field on Page Load Using Jquery
Inlining Ecmascript Modules in HTML
How to Use Square Cursor in a HTML Input Field
Directly Reference HTML Elements
How to Tell Google Translate to Not Translate a Section of a Website
Load JSON from Local File with Http.Get() in Angular 2
How to Programmatically Force an Onchange Event on an Input
Increment a Number in a String in with Regex
How to Clear a Chart from a Canvas So That Hover Events Cannot Be Triggered
Class Methods as Event Handlers in JavaScript
Save JSON String to Client Pc (Using HTML5 API)
Appending Form Input Value to Action Url as Path
How to Defer Inline JavaScript
How to Filter Input Type="File" Dialog by Specific File Type
How to Make Recaptcha a Required Field
What Tag in HTML Should I Use Without Special Meaning, Only to Carry Meta Data