0

Hello i want to display the value in alert . I passed the php value as a parameter in jquery and when i display that value in alert it shows empty Code is here

<button type="button" onclick="topSharedPosts('<?php echo $postID; ?>')" class="btn btn-success" value="<?php echo $postID; ?>"> Facebook </button>

Jquery Function

function topSharedPosts(id) {
       alert(id);
}
  • 4
    (1) What is the *actual* resulting client-side HTML? (2) jQuery isn't being used here at all, so that tag/reference/etc. is entirely irrelevant. – David Feb 11 '16 at 17:30
  • You should consider wrapping that $postID in htmlentities($postID) to avoid XSS. After you load the page in your browser just view the HTML generated to make sure it has the value you expect. If not, it may be your $postID value is different then what you expect. – Sean Feb 11 '16 at 17:31
  • Try `ctrl + f5` cache problems ... – rray Feb 11 '16 at 17:32
  • Code seems to be fine. Check $postID, inspecting – Gaurav Rai Feb 11 '16 at 17:33
  • thanks to all for the help – Waleed Raja Feb 13 '16 at 08:46

1 Answers1

1

It's working for me:-

  1. your file must have .php extension not .html.

Check the below code:-

Alert.php:-

<?php 
$postID = 2;
?>
<button type="button" onclick="topSharedPosts('<?php echo $postID; ?>')" class="btn btn-success" value="<?php echo $postID; ?>"> Facebook </button>

<script type = "text/javascript">
function topSharedPosts(id) {
       alert(id);
}
</script>

Note:- there is no jquery in your code and my code. It's pure javascript. I have taken $postId value to check that code works or not, and it works fine.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98