Javascript Function Accepting Php Variables
I'm drawing a complete blank why this isn't working. I can do it with one variable passing through, but not two. When I use actually numbers like getnt(1,2) it works. It's just not
Solution 1:
If the ID and pnID are strings, enclose them with brackets like this.
<body><?phpecho"<a href='#' onclick=\"getnt('$nid','$pnid')\">VIEW</a>";
?></body>
If still not working, You can debug your code
Solution 2:
You could always try:
<scripttype="text/javascript">functiongetnt(nid,pnid) {
window.location = "nt.php?nid=" + nid + "&pnid=" + pnid;
}
</script><body><ahref="#"onclick="getnt(<?phpecho$nid; ?>,<?phpecho$pnid; ?>)">VIEW</a></body>
Solution 3:
Your question is probably best answered by looking at the rendered HTML source.
In any case, here's how I'd do it using graceful degradation
<scripttype="text/javascript">functiongetnt(element) {
var href = element.href;
var nid = element.getAttribute("data-nid");
var pnid = element.getAttribute("data-pnid");
returntrue;
}
</script><p><ahref="nt.php?nid=<?phpecho$nid?>&pnid=<?phpecho$pnid?>"data-nid="<?phpecho$nid?>"data-pnid="<?phpecho$pnid?>"onclick="return getnt(this)">VIEW</a></p>
Post a Comment for "Javascript Function Accepting Php Variables"