Verification: a143cc29221c9be0

On click event in php

On click event in php

Another way of linking button

Demo of two types of buttons with code


Using hyper link

search engine friendly page design

Opening in a new window

onClick=parent.open()

Managing from a child window

Read More on Child window control in our JavaScript section.

We can display buttons in Child window and manage the main ( parent ) window by using buttons. We can make the main window navigate to different page from the child window.

Check this demo on using buttons to manage main window.

To display above button , source is here

Button with Style


DEMO of Buttons with CSS properties

Using bootstrap style


We can change size of these buttons
Read more attractive buttons using bootstrap in JQuery section.

Using image to link

Use jQuery to Execute the PHP Function With the onclick() Event

We can use jQuery to execute the onclick() event by writing a function that will execute the PHP function. For example, create a PHP file echo.php and write a function php_func(). Write a message Have a great day inside the function and call the function. In another PHP file, write some jQuery inside the script tag. Do not forget to link the webpage with the jQuery source. In the HTML, write a button tag with onclick() attribute. Write the value of the attribute as the test() function. Write the text Click between the button tags. Create an empty div tag below the button. Write the function test() inside the script tag. Write an AJAX method with the URL as echo.php and write a success() function with result as the parameter. Then use the selector to select the div tag and use the text() function with result as the parameter.

In the example below, we use the AJAX method to perform an asynchronous HTTP request. The URL species the URL to send the request to, and the success() function runs when the request is successful. The method sends the request to the echo.php file, which resides in the same location as the current PHP file. The request becomes successful, and the success() function returns the result, and it gets printed.

Example Code:

#php 7.x

Output:

Have a great day

Use Plain JavaScript to Execute the PHP Function With the onclick() Event

This method uses JavaScript to execute a PHP function with onclick() event. For example, write a PHP function php_func() that displays the message Stay Safe. Create a button with the name Click using the button tag. Specify the onclick() function as an attribute with the clickMe() function as its value. Write the function clickMe() inside the script tag. Create a variable result and call the php_func() in it inside the PHP tags. Use the document.write() function with the result as the parameter to print the output.

In the example below, the JavaScript function clickMe() executes when we click the button. Then, the PHP function php_func() executes from the JavaScript function. The result variable stores the result from the PHP function, and it gets printed.

Code Example:

#php 7.x

function clickMe(){
var result =""
document.write(result);
}

Output:

Stay Safe