How to Add PHP Variables in a Jquery Notification [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
passing variables from php to javascript
I am using this awesome jQuery Stick Notification Plugin which creates notifications upon clicking various buttons.
I used the following code to display the notification box...
$(".notify").click(function() {
$.sticky('The page has loaded!');
});
Can i make it display some PHP variables in place of static text message?
Hope i've made it clear enough.

Without making asynchronous HTTP calls, you will have to insert the PHP variable at server-side:
$(".notify").click(function() {
$.sticky('<?php echo htmlentities($message); ?>');
});
Wrap it with htmlentities() just in case $message contains some chars that make the JavaScript string invalid.

yes you can like
$(".notify").click(function() {
$.sticky('<?php echo "The page has been loaded"; ?>');
});

Related

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.

Is it possible to apply jquery to content rendered by external php (ajax)? [duplicate]

This question already has answers here:
Events triggered by dynamically generated element are not captured by event handler
(5 answers)
Closed 8 years ago.
page-one.php contains such jquery
$.post("___for_ajax_process.php", data_to_send_ajax_post, function(data_edit_content) {
$('#show_result').html(data_edit_content);
});
in #show_result i see content from ___for_ajax_process.php
Rendered content contains many checkboxes and want to create check all. check all is named draft_check_all.
At first want to check what happens if I click the checkbox.
$("#draft_check_all").click(function(){
alert ( 'click test' );
});
And I do not see alert ( 'click test' ); No popup at all.
Then View source and I do not see source code for content rendered by ___for_ajax_process.php
As understand in such way can not apply jquery to content from ___for_ajax_process.php? What if place $("#draft_check_all").click(function(){ in ___for_ajax_process.php? Are there any solutions for such situation?
Solution
placed jquery in external php and all works!
A better solution would be event delegation.
$('#show_result').on('click', '#draft_check_all', function () {
...
});

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 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