-2

I am trying to get a variable from my javascript function while I'm coding in PHP.

my javascript which is included in the page:

function subAmt(empid, subid){
    return 4;
}

my attempt to call that function:

$amt = echo "subAmt(3,5);" ;
  • 1
    **CLIENT SIDE** javascript is not compatible with **SERVER SIDE** PHP – Derek Pollard Feb 04 '16 at 21:31
  • PHP is executed "server side" before the page is send to the client. JavaScript is executed "client side" after the page is recieved by the client. But you can post back JavaScript variables to the server with get or post methods and then use them in your PHP code – Nillervision Feb 04 '16 at 21:35

1 Answers1

0

You need the script tags I think?

echo '<script type="text/javascript">'
   , 'subAmt(3,5);'
   , '</script>'
;

Please refer to this question: How to call a JavaScript function from PHP?

Community
  • 1
  • 1
Kal
  • 2,239
  • 6
  • 36
  • 74