php - Passing phone number to Javascript function -


im attempting pass phone number button on html page, problem each time page loads id of button (may change) cant capture id ( dont think ).

the problem lies in seems pass integer, misses off 0 @ start. there anyway pass via string, believe resolve issue.

$phone_details[] array of details..

<script>  function shownumber(id)  {   alert(id);  } </script> 

html

<input type='button' value='".$phone_details[1]." ".$phone_details[2]."' onclick='shownumber(".$phone_details[0].")'>  

you loading php, aren't you? missing additional quotes:

<input type='button' value='".$phone_details[1]." ".$phone_details[2]."' onclick='shownumber(\"".$phone_details[0]."\")'>  

see added \", ensure sending "0123" (string) instead of 0123 (number) , therefore keep leading 0.

you can test simple alerts. first 1 without quotes, second quotes:

alert(06512300);  alert("06512300");

if doesn't work, should ensure printing phone_details[0] string. not think that's issue, if is, check: http://us3.php.net/manual/en/language.types.type-juggling.php


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -