JavaScript Calling a PHP function through an HTML Link (no form) calling function through pointer

You will need to use AJAX to accomplish this without leaving the page. Here is an example using jQuery and AJAX (this assumes you have already included the jQuery library):

First File:

<script language="javascript">

$(function(){
    $('#mylink').click(function(){
        $.get('/ajax/someurl', {linkText: $(this).text()}, function(resp){
           // handle response here
        }, 'json');
    });

});

</script>

<a target='_blank' href="#" id="mylink">This text will be passed along</a>

PHP File:

$text = $_REQUEST['linkText'];
// do something with $text here
Answer:1

You'll need to have a JS function which is triggered by an onclick event which then sends an AJAX request and returns false (so it won't be redirected to a new page in the browser). You can do the following in jQuery:

jQuery:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
    $.get("myfile.php");
    return false;
}
</script>

And in your page body:

<a target='_blank' href="#" onclick="doSomething();">Click Me!</a>

In myfile.php:

You can add whatever function you want to execute when the visitor clicks the link. Example:

<?php
echo "Hey, this is some text!";
?>

That's a basic example. I hope this helps.

Answer:2

If you are familiar with jQuery, you could do the following, if you don't want the site to redirect but execute your function:

in your html head:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

the link:

<a target='_blank' href="#" onclick="$.get('ajax.php');">Execute function</a>

in ajax.php you put in your function to be executed.

Answer:3

Maybe something like this:

<a target='_blank' href="#" onclick="return sendText(this);"></a>
....
<script>
function sendText(e)
{
 $.ajax({
         url: '/your/url/',
         data: {text: $(e).html()},
         type: 'POST' 
        });
}
</script>
Answer:4

You can use query strings for this. For example if you link to this page:

example.php?text=hello

(Instead of putting a direct link, you can also send a ajax GET request to that URL)

Inside example.php, you can get the value 'hello' like this:

<?php
$text = $_GET['hello'];

Then call your function:

myfunction($text); 

Please make sure you sanitize and validate the value before passing it to the function. Depending on what you're doing inside that function, the outcome could be fatal!

This links might help:

Answer:5

Here's an overly simplistic example of what you're trying to do..

Your link:

<a target='_blank' href="somefile.php?action=Some+Action">Some Action</a>

Your PHP file:

<?php

if (isset($_GET['action']))
{
    // make sure to validate your input here!
    some_function($_GET['action']);
}
Answer:6

I have a form in Angular setup like the following. Users can make changes and submit one at a time and it works as expected but I'd like to add a "Submit All" that would submit each item one at a ...

I have a form in Angular setup like the following. Users can make changes and submit one at a time and it works as expected but I'd like to add a "Submit All" that would submit each item one at a ...

  1. submit multiple forms with one button
  2. submit multiple forms with one button powerapps
  3. submit multiple forms with one button jquery
  4. submit multiple forms with one button angular
  5. submit multiple forms powerapps
  6. submit multiple forms with one button ajax
  7. submit multiple forms with one button django
  8. submit multiple forms with one button php
  9. submit multiple forms with ajax
  10. submit multiple forms with one button angular 2
  11. submit multiple forms with one button asp.net mvc
  12. submit multiple forms
  13. submit multiple forms with one button html
  14. submit multiple forms with one button jquery ajax
  15. submit multiple forms at once
  16. submit multiple forms with one button rails
  17. submit multiple forms php
  18. submit multiple forms jquery
  19. submit multiple forms django
  20. submit multiple forms using ajax

I am trying to detect Hebrew characters using a regular expression. From what I have read, this is any character in the Unicode range 0x0590-0x05ff. However, the following doesn't work: // ...

I am trying to detect Hebrew characters using a regular expression. From what I have read, this is any character in the Unicode range 0x0590-0x05ff. However, the following doesn't work: // ...

  1. hebrew unicode range

I have a page on my site where a user can select boxes to return a query based on their selection. For example, my header looks like: _Burgers _Fries _Beverage _small _medium _large The ...

I have a page on my site where a user can select boxes to return a query based on their selection. For example, my header looks like: _Burgers _Fries _Beverage _small _medium _large The ...

I am trying to build an extremely simple responsive navigation menu. Am having some problems here. When I resize the window equal to or lower than 768px in width, the responsive menu will not work. ...

I am trying to build an extremely simple responsive navigation menu. Am having some problems here. When I resize the window equal to or lower than 768px in width, the responsive menu will not work. ...

  1. responsive navigation menu css codepen
  2. responsive navigation menu css
  3. responsive navigation menu jquery
  4. responsive navigation menu bootstrap
  5. responsive navigation menu jquery codepen
  6. responsive navigation menu css free download
  7. responsive navigation menu codepen
  8. responsive navigation menu with submenu
  9. responsive navigation menu with dropdown
  10. responsive navigation menu css jquery
  11. responsive navigation menu examples
  12. responsive navigation menu template
  13. responsive navigation menu css examples
  14. responsive navigation menu bootstrap codepen
  15. responsive navigation menu css only
  16. responsive navigation menu bootstrap free download
  17. responsive navigation menu with submenu bootstrap
  18. responsive navigation menu css bootstrap
  19. responsive navigation menu css code
  20. responsive navigation menu bootstrap 4