This question already has answers here:
javascript variable into php
(3 answers)
Closed 8 years ago.
i have php code like this
<?php
$queryitemkits="select item_id, cost_price, unit_price from items where item_id='JAVASCRIPTVARIABLE'";
$resultqueryitemkit = mysql_query($queryitemkits) or die('Query failed item kits!');
while($rowitem = mysql_fetch_assoc($resultqueryitemkit))
{
$itemcostprice=$rowitem['cost_price'];
$itemunitprice=$rowitem['unit_price'];
}
?>
and i have javascript variable named ui.item.value
how to insert that ui.item.value javascript variable to replace JAVASCRIPTVARIABLE in above PHP code?
Remember PHP is on the server, and the variable "JAVASCRIPTVARIABLE" in the client, you need to submit the variable to the server, also you need input validation, JAVASCRIPTVARIABLE it can be empty when is received on the server.
Related
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 1 year ago.
I am new in PHP and javascript and need help with the following code
I want to get the value from browser URL that tag with "org" and use it in javascript; as example "http://localhost/nmt/index.php?org=table1" I want to put the "org" value inside the URL/ inside the POST $.post("ch1.php?org=table1", instead of table1 put the GET value
This is the part from code
$(document).ready(function () { showGraph1(); }); function showGraph1() { { $.post("ch1.php?org=table1", function (data) { console.log(data);
That If possible replace table1 with the value from URL
You can inject your variable into the javascript.
<script>
var data = <?php echo json_encode($_GET["org"]); ?>;
</script>
You also can get the url parameter directly from js.
This question already has answers here:
Get only filename from url in php without any variable values which exist in the url
(13 answers)
Closed 4 years ago.
I have these urls and I need to remove the first part to get the file name:
http://isonex.ru/upload/iblock/ebd/ebdbd2a3961fc73170978ae4995b5a4b.jpeg
http://isonex.ru/upload/iblock/62a/62a5e49b20e498bfef00d81fa03403c8.jpeg
How can I clean the url to get only the file names?
For example:
ebdbd2a3961fc73170978ae4995b5a4b.jpeg
62a5e49b20e498bfef00d81fa03403c8.jpeg
c0004e9ab6e749b4bfc70d652722e966.jpeg
Since, you tagged PHP, you can use basename function.
<?php
echo basename("http://isonex.ru/upload/iblock/ebd/ebdbd2a3961fc73170978ae4995b5a4b.jpeg"),"\n";
echo basename("http://isonex.ru/upload/iblock/62a/62a5e49b20e498bfef00d81fa03403c8.jpeg");
OUTPUT:
ebdbd2a3961fc73170978ae4995b5a4b.jpeg
62a5e49b20e498bfef00d81fa03403c8.jpeg
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 5 years ago.
Please help me on how to concatenate php code on jquery html:
$('div#divID').html('<?php echo $fib->getFibonacci( " + limit + "); ?>");
in order to pass the value: var limit = $('#inputID').val() of input after clicking the button. Thank you!
PHP Code
class Fibonacci {
public function getFibonacci($num){
...
return $fib;
}
}
$fib = new Fibonacci();
HTML
<input type="text" id="inputID">
<button id="buttonID">
<div id="divID">
JS
$('#buttonID').click(function() {
var limit = $('#inputID').val();
$('div#divID').html("<?php echo $fib->getFibonacci( " +limit+");?>");
});
Goal: to pass the value on input when calling Php function using jquery syntax.
Is there possible way? Thank you.
In your example you are trying to pass JS variable as argument to PHP function. It is not possible this way, because PHP is server side, and JS is client side (in your case) scripting language.
What you can do is on click to calculate "limit" value, pass it using AJAX to "getFibonacci" function in php and to append into html tag returning value. That is one way of interaction between PHP and Front-end JS.
This question already has answers here:
Send PHP variable to JavaScript function [duplicate]
(6 answers)
Closed 6 years ago.
I have js code which is inside echo statement (which is retried using ajax call).
I need to send another ajax request based on the first result. So I need to assign a php variable inside a js variable (php variable is retrieved from database during first ajax call)
echo '<script>
echo '<script>// SEINDINGM REQUEST FOR SELECTED DAY
$("#dayName").on("change", function(){
// GRABBING THE SELECTED VALUE
var day = $(this).val();
var uid=//Here I want to assign the php variable //;
alert(uid);
alert(day);
</script>';
replace
var uid=//Here I want to assign the php variable //;
with
var uid='.$myVariable.';
PHP doesn't care if this value will end up in JavaScript code. It just writes the content wherever you want it to be. The document will arrive at the client as usual HTML including the already inserted variable content. Then it will be normally executed by JavaScript.
If the variable's content is a String then you have to write it like:
var uid="'.$myVariable.'";
Here are more information and different options how to include variable content within echo php - insert a variable in an echo string
echo '<script>
$("#dayName").on("change", function(){
// GRABBING THE SELECTED VALUE
var day = $(this).val();
var uid='.$myVariable.'
alert(uid);
alert(day);
</script>';
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 9 years ago.
I have a Javascript variable as "name" I want to add that to my php code. The php code uses the JS variable for a select statement. This is what I am Trying, but I am getting a syntax error;
<script type="text/javascript">
function fillform(name){
<?php $name = "SELECT * FROM table_name WHERE name = ". ?> name <?php ." "; ?>
console.log(<?php echo $name; ?>);
}
</script>
PHP code is executed by the server.
Then the server sends the output of that code to the client in html form..
Javascript is executed by the client so you cannot combine them.
A solution could be the use of AJAX which allows javascript to call a php file and get the output of the executed code..