0

This snippet is of jQuery code is inside the php already...How do I access variables inside the jquery code

<?php


echo'
    $( "#searchButton" ).click(function() {


    //    location.reload();
    alert(\"$folder\"); //This is causing error
    });'

?> 
2
  • Try echoing the variable there instead of just printing the string name of the variable? Commented Nov 28, 2018 at 7:19
  • @CertainPerformance like how? Commented Nov 28, 2018 at 7:27

2 Answers 2

0
<?php
echo'
   $( "#searchButton" ).click(function() {
       alert("'.$folder.'");
   });';
?> 
Sign up to request clarification or add additional context in comments.

14 Comments

It shows this in the alert box <?php echo $folder;?>
I have just updated my code. Remove the "" quotation on alert
It gives this error now SyntaxError: expected expression, got '<'
is it a .php file?
Try - alert( " ' . $folder .' ");. (spaces for understanding.)
|
0

try this as echo will return a value to the alert.

alert(<?php echo $folder ?>);

3 Comments

It gives this error SyntaxError: expected expression, got '<'
The above answer will work for a .js file
Edited the code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.