-3

<script src="https://cdn.jsdelivr.net/sweetalert2/6.3.2/sweetalert2.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/sweetalert2/6.3.2/sweetalert2.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
<a onclick="contactAdvertiser()" href="#">Contact Advertiser</a>
<script>
function contactAdvertiser() {
swal({
  title: 'Contact Advertiser',
  type: 'info',
  html:
    'Interested in this product/service? Contact the advertiser!<br> ' +
    '<a style="text-decoration: none; color: #FFC107;" href="tel:'.$item->phonenumber.'"><b>Call Advertiser</b></a><br> ' +
    '<b><a style="text-decoration: none; color: #536DFE; href="sms:'.$item->phonenumber.'?body=Greetings%2C%20I%20am%20interested%20in%20your%20product%2Fservice%20posted%20on%20OfferMoon.%20$
  showCloseButton: true,
  confirmButtonText:
    'Done',
})
}
</script>

I do not know what is wrong with my code, I have tried many times to fix the "contactAdvertiser function not defined".

UPDATED CODE:

'<a style="text-decoration: none; color: #FFC107;" href="tel:'+ <?php $item->phonenumber ?>+'"><b>Call Advertiser</b></a><br>' +
    '<b><a style="text-decoration: none; color: #536DFE; href="sms:'+ <?php $item->phonenumber ?>+'?body=test"</a>' +
Melon
  • 11
  • 5

1 Answers1

0

Your updated code is almost there - the problem is you still don't understand how PHP works

try this

'<a style="text-decoration: none; color: #FFC107;" href="tel:<?php $item->phonenumber ?>"><b>Call Advertiser</b></a><br>' +
'<b><a style="text-decoration: none; color: #536DFE; href="sms:<?php $item->phonenumber ?>?body=test"</a>' +

the phonenumber is "injected" by PHP within this string, "tel:phonenumber ?>">"

The problem with

'<a style="text-decoration: none; color: #FFC107;" href="tel:'+ <?php $item->phonenumber ?>+'"><b>Call Advertiser</b></a><br>'

is that if the phonenumber is a string (contains spaces in the middle for example) your javascript will end up

'<a style="text-decoration: none; color: #FFC107;" href="tel:'+ 02 1234 5678 +'"><b>Call Advertiser</b></a><br>'

and that's not valid javascript either

using

'<a style="text-decoration: none; color: #FFC107;" href="tel:<?php $item->phonenumber ?>"><b>Call Advertiser</b></a><br>'

it becomes

'<a style="text-decoration: none; color: #FFC107;" href="tel: 02 1234 5678"><b>Call Advertiser</b></a><br>'
Jaromanda X
  • 53,868
  • 5
  • 73
  • 87