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

12
  • before you click, any other errors or warnings in the developer tools console? By the way, it's unusual to see a <link in the body of HTML Commented Jan 21, 2017 at 8:08
  • '.$item->phonenumber.' ... well, that's not kosher javascript - you MUST be getting an error in the console before you click about some sort of syntax error Commented Jan 21, 2017 at 8:12
  • @JaromandaX - nope, no errors at all. Commented Jan 21, 2017 at 8:13
  • No, no, this is in PHP, and that gets the user's phone number. @JaromandaX Commented Jan 21, 2017 at 8:13
  • 1
    No no, this part of the code isn't PHP - it's javascript ... the total lack of <?php ... ?> tells me that - also the lack of [php] tag Commented Jan 21, 2017 at 8:14

1 Answer 1

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>'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.