How to add my html javascript popup to my php function? [duplicate] - php

This question already has answers here:
Accessing session from TWIG template
(5 answers)
Closed 9 months ago.
I want to add my javascript popup code which is in an html file to my php function.
It's a visitor counter in php. I want when visitors visit the page 4 times my popup html js is displayed

Do you just mean like this?
if ($increment == true) {
$compteur_actuel = $session->get('compteurClicsFreemium', 0);
$session->set('compteurClicsFreemium', $compteur_actuel+1);
if ($compteur_actuel > 4) {
?>
<div>
Your HTML code here
</div>
<?php
}
}

Related

Call a php function when an html link is clicked [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 6 years ago.
I want to call a PHP function when someone clicks an html link. I don't know how to do it. Please help.
Didn't get a code?
<?php
function sendCode(){
//code
}
?>
Do it like this:
Didn't get a code?
<?php
if(isset($_GET['sendcode'])){
sendCode();
}
function sendCode(){
//code
}
?>

Change the url after clicking the submit button [duplicate]

This question already has answers here:
Redirecting after form submission with user input in the URL
(3 answers)
Closed 8 years ago.
I have a form that filters the products by some characters such as size/price etc..
I would like to change the url variables values according to the filter result for example:
Before submit:
www.exmaple.com/product.php
after submit
www.example.com/product.php?size=1&price=300
How can I do that?
Try something like this
if(isset($submit))
{
//After clicking the button , do some operations here....
//Your code...
//More code...
header("location:product.php?size=1&price=300");
}
EDIT :
This is most common error check this thread. Also, if that doesn't work. Replace your header with
echo "<script>document.location.href=product.php?size=1&price=300</script>";

copy all contents of a td to another in another div [duplicate]

This question already has answers here:
jQuery copying content between DIVs
(4 answers)
Closed 9 years ago.
I do need to know how to copy the contents of an entire html td td and play for another from a different button that was clicked?
both the button when the content comes from the database
was thinking about this for jquery but not know where to start: (
This should go with:
$('td').clone().appendTo('.newtd');
you trigger that with eg following:
$('#triggerbtn').click(function() {
$('td').clone().appendTo('.newtd');
}
markup for the button:
<div id="triggerbtn">Click me for clone</div>
the .newtd is the class of the new td you want to clone your content. you can use an id declared with a #newtd as well.

how to run php code onclicking an image [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I run PHP code when a user clicks on a link?
I have an image .
<image name="" src="">
I have a php code that needs to be run only after the image has been clicked.
<?php
$var = somthing;
if(condition)
{
sql stmts;
}
?>
like that.
Both are in the same php page. PLease help me to sort out this problem.
Thanks..
You can send a request with javascript. With jQuery that would look like this:
$.get("yourfile.php?function=imageClick", function(data){});
In your php somewhere at the top add:
if($_GET['function'] == 'imageClick'){
// do your php stuff
}
You can't run PHP code on the client side.
You can do that through an AJAX call: http://www.w3schools.com/ajax/default.asp

how can change value of a div [duplicate]

This question already has answers here:
How can I convert language of a div?
(4 answers)
Closed 7 years ago.
"<div id="diva">this is div a</div>"
"<div id="divb"> this is div b</div>"
now how can I change the text of div dynamically by button click. here also mention that all text come from a database. when I click the button then it detects the div id and replace the text with desire text.
All code will be in PHP.
This will work once the page is being loaded:
document.getElementById('diva').innerHTML =
<?php echo functionThatReturnsSomeValue(); ?>;
Dynamically, you would need to do an AJAX call on the PHP file which outputs a value. You'd be better off if you used a JS framework such as jQuery, rather than implementing the AJAX call yourself.
PHP cannot modify the content of the page after it has been served to the browser. However this would be trivial with a JavaScript Library such as jQuery.

Categories