-1

There is a javascript function with a parameter :

<script type="text/javascript">
   function afficheHelp(aide_htm)
   {
     ... // I want to code PHP here with the parameter "aide_htm"
   }
</script>

How to use the "aide_htm" javascript parameter inside PHP code within the javascript function ?

3
  • Why do people downvote and leave no comment? Commented May 3, 2013 at 7:59
  • Something like this would assign $phpVar to your jscript var aide_htm. <script type="text/javascript"> function afficheHelp(aide_htm) { <?php echo "aide_htm ='" . $phpVar . "'; ?> } </script> Commented May 3, 2013 at 8:04
  • the downvotes are because you could find the answer by doing a quick search on this site for related questions. Commented May 3, 2013 at 8:06

2 Answers 2

2

You need to invoke serverside code from your clientside Javascript. This is commonly done with an Ajax call. How to exactly do this depends enormously on what you want to do with the result and which JS library you are using. I'd recommend reading up on Ajax in general, and jQuery or Mootools on how to execute a call specifically.

Sign up to request clarification or add additional context in comments.

Comments

1

Javascript is client side and executed in the users browser whereas PHP is server side and executed on your server as such you can't use javascript directly in PHP. You can however use javascript to perform an AJAX request to PHP on your server. If you're using jQuery have a look at http://api.jquery.com/jQuery.ajax/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.