0

I have to show the contact num from database when user click on the button.. but when I use php in javaScript it doesn't work for me... here is HTML

<button name="showNo" id="phone1" onclick="myFunction()"><span>Show Phone No</span></button>
<p id="show">******</p>

here the JavaScript

<script type="text/javascript">
function myFunction(){
    var hsh = document.getElementById("show");
    if ( hsh.value === "******" )
        hsh.value = "<?php echo $contact; ?>";
    else
        hsh.value = "Open Curtain";
}
</script>

is there any other method to do this,,?

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40

1 Answers1

2

Try this, p tag does not have value so you need to use innerHTML to get data from it and set it

var hsh = document.getElementById("show").innerHTML;
if(hsh === "******"){
    document.getElementById('show').innerHTML = "<?php echo $contact; ?>";
}else{
    document.getElementById('show').innerHTML = "<?php echo 'Open Curtain'; ?>";
}
M.Hemant
  • 2,345
  • 1
  • 9
  • 14