Call number by clicking on a p

-3

I have a question, and it's like doing so that when you click on a phone number, make a href="tel: ######"

But I need you to call the number that I bring with php from the database

<p><?php echo $row['telefono']; ?></p>

I've tried something like that ... but I know it will not work:

<p href="tel:<?php $row['telefono']; ?>"><?php echo $row['telefono']; ?></p>
    
asked by Alejandro 03.01.2018 в 19:21
source

3 answers

1

This should work, although I have not been able to prove it because I do not have a phone right now:

<p data-tel="tel:<?php echo $row['telefono']; ?>"><?php echo $row['telefono-friendly']; ?></p>

That is, you show the phone in a friendly format and place the phone to call in a data type attribute called tel.

Then in jQuery for example:

            $("p").click(function() {
                window.open($(this).data("tel"));
            });
    
answered by 04.01.2018 / 09:52
source
1

I recommend you use JavaScript to perform the operation you want. A onclick action is added to the desired element and you can use the element when you click.

  

NOTE: If the item is "< a >" that has an action in the click you must add "preventDefault" if you do not want it to be done

I'll add an example of pure javaScript and another with jquery:

JS Pure

function llamarFunction(e){
    window.location.assign(e.getAttribute("href"));
}
<p id="callButton" href="tel:666000000" onclick="llamarFunction(this)">666000000</p>

JQuery

$("#callButton").click(function(e) {
    window.location.assign($(this).attr('href'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="callButton" href="tel:666000000">666000000</p>
  

I've put hard data for the example

    
answered by 04.01.2018 в 10:57
0

Thank you very much for your contributions, I have been testing and the simplest solution and that works for me I leave it here for if someone else has this doubt.

<a href="tel:<?php echo $row['telefono']; ?>"></a>
    
answered by 04.01.2018 в 13:48