can this function be call when we click on checkbox? [duplicate] - php

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 7 years ago.
<input type="checkbox" name="tag_1" onclick="<?php echo base_url('zohaib_work_controler/activity/'.$row->id.'/'.$row->active);?>" value="yes" <?php echo ($row->active==1 ? 'checked' : 'unchecked');?>> </td>
I wan't to run the php function when click on the checkbox.
which show the activity of the user.
but it can't run why?

PHP gets parsed on the server, which delivers the HTML to your user's browser when they request it. The click then happens in the browser. To run a function when the user clicks one can do one of 2 things:
1) Write the function in Javascript if no server assets are needed, or
2) Use Javascript to make an AJAX call to the server where your PHP function is run and then the result returned.

Related

Display a message when a form is submitted to run a PHP script [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 5 years ago.
I am a bit puzzled with this one. I am trying to display a "Please wait..." message when a form is submitted (see code below) that is running PHP on the same page. It appears to run the PHP and then reloads the page.
I have added the sleep(10) just for testing purposes.
Can anyone help?
Thanks,
John
EDIT: Ok, I now understand the difference between server and client side. So - my question is: How do I display a message when the submit is clicked and before the PHP is run?
<?php
if (isset($_POST['submit'])) {
echo "Please wait..."; //display a loading message
}
?>
<form action="test.php" method="post">
<input type="test"></input>
<button name="submit" type="submit">SEND</button>
</form>
<?php
if (isset($_POST['submit'])) {
sleep(10); //run a script that takes a while
}
?>
Your PHP script won't be able to send the message and then redirect. You need to use JavaScript on the wait page and redirect. If you are not trying to redirect, not sure why the please wait message would be needed.
setInterval(function(){window.location.href="your_url" }, 10000);
For the download script, it needs to set the content type to PDF which means you can't send anything before that (header already sent error otherwise).
Two possible solutions:
1. You should display your 'please wait' on the page where the user clicks and open the download script in another page.
2. The download page can display the html and then use an iframe for downloading the file. Using jQuery and iFrame to Download a File

Php parameterized function call from html [duplicate]

This question already has answers here:
How to call a PHP function on the click of a button
(13 answers)
Closed 7 years ago.
I have a problem with calling a phpfunction from a onclick() event.
<button onclick=delete($a) >click here</button>
<?php
Function delete($a)
{
----statements----
}
?>
Please help me solving this functiom call
You cannot call a php function from a javascript onclick event that way. php is strictly server side, the only way is to make an ajax call to a script that will run the function and return the result. Once the page is served, all trace of php disappears, there is no reference or anything of php left in the client side.

Call a php function when clicks on a html tag within the same page [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 8 years ago.
/*
//Want to call a php function when on clicking a tag
// Want to call a php function when on clicking a tag
//Want to call a php function when on clicking a tag
// Want to call a php function when on clicking a tag
*/
<?PHP
//starting of a function
function callfun(id)
{
//prints the parameter of the function
echo id;
}
//call a php function when clicks on a paragraph
echo '<p id="xyz" onClick="callfun(id)">Click Me </p>';
?>
/*Want to call a php function when on clicking a tag
Want to call a php function when on clicking a tag
Want to call a php function when on clicking a tag
Want to call a php function when on clicking a tag
*/
You can use some technology to do this. One way is to call another script using ajax call for example. If you don't know what ajax is here is an explanation http://bg.wikipedia.org/wiki/Ajax
Another think you can try is just using javascript and translate your function in javascript.
PHP is not working like that.
I suggest you to watch some tutorials about the language technique.
First of all you need to understand the difference between the server side and the client side.
PHP is not running on the client side!
For your need you must use AJAX function which will call a request to the server.That request will execute the PHP function and return the answer to the clients browser.After that you can handle it for your needs.

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 i check if an element is visible in php? [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 years ago.
i have a couple of variables that i want to save or not save to a database depending on whether or not i have set them as hidden/visible in a javascript function, i have searched for a while but cant find anything. Thanks!
That's absolutely impossible since PHP runs on the server while JavaScript and CSS are client-side.
The only thing you can do is checking if the element is visible using JavaScript and sending that data to your PHP script, e.g. via a hidden <input> field.
You can also have this alternative. NOTE that the page has to refresh before this take effect (i.e. before PHP has knowledge of what was going on)
//Your JavaScript
function setHidden()
{
document.getElementById('elementForVar1').visibility = 'hidden';
//use this to indicate field/variable is hidden. PHP will use this later
document.getElementById('elementForVar1HiddenField').value = 1;
}
declare hidden fields in your form to store the states of the variables
<form name="xxx">
<input type="hidden" id="elementForVar1HiddenField" name="elementForVar1HiddenField" value="0" />
</form>
Your javascript simply set the value of the hidden field to 1 indicating var1 is hidden
<?php
if($_POST['elementForVar1HiddenField'] == 1)
//variable was hidden
?>

Categories