0

Hey guys I have this populated search form that will bring a table of people based on search result. I need to be able to get the php variable that has the username I am trying to get, then that will get sent over to .php file using the JQuery UI which will open a notes window.

So here:

username, other, other , notes - this is a link and once clicked the following is called:

$(document).ready(function () {
    $("#NotesAccessor").click(function () {

      alert(notes_name);
      run();
    });
    });

which leads to :

function run(){ var url = '/pcg/popups/grabnotes.php'; showUrlInDialog(url); }

to a function that opens the Jquery Dialog.

I need to access the username of the based notes that was clicked....if there was 20 results of different names, david, joe, john, etc... I click the notes with david as username, I need that to be sent over to the file that is opening so I can display the based notes on the appropriate username.

Here is my php:

.........
    <td>
        $csvusername
    </td>
.........
    <td>
    ";
      if ($checkNotes[1] == 'No')
    {
        echo "None";
    }
    if ($checkNotes[1] == 'Yes')
    {
            echo "<a href='#' id='NotesAccessor'>Click to access</a>";
    }
    echo "
    </td>
........

Let me know if this makes sense to you. I am kinda stuck on this and could use a hand :)

David

David Biga
  • 2,763
  • 8
  • 38
  • 61

2 Answers2

1

I can't tell what PHP variable you are trying to get, but generally, you can do:

<!-- /myScript.php?myVar=helloWorld -->
<script type="text/javascript">
    $(document).ready(function(){
        var myPhpVar = <?php echo $_GET['myVar']; ?>;
        alert(myPhpVar);
    });
</script>
user1477388
  • 20,790
  • 32
  • 144
  • 264
  • 2
    Beware of XSS attacks on user input and echoing without cleaning. – span Feb 09 '13 at 23:11
  • So using the $_GET['the php value I need to get]; I can get the value of the php value I want on the same page? – David Biga Feb 09 '13 at 23:12
  • @user1477388 there is an issue with this, I have not passed the value at all? I am trying to get it. – David Biga Feb 09 '13 at 23:19
  • @DavidBiga In order to "get" the value of $_GET, you have to put it in the query string. So, if accessed the URL `/myScript.php?myVar=helloWorld` and used my code, you would get "helloWorld" output in an alert box via JavaScript. To read more about retrieving client data via PHP, read http://www.tizag.com/phpT/postget.php. – user1477388 Feb 10 '13 at 13:38
  • @span & @DavidBiga Yes, do not trust anything that a user gives you (anything that comes from the client). You can usually get away with simply escaping special characters by using `` but you should consider looking up "php security" to use something even more secure. – user1477388 Feb 10 '13 at 13:42
0
<script>
var x = '<?php echo $variable; ?>';
or
var x = '<?php echo my_function(); ?>'; 
</script>


<?php
function my_function()
{
  return $variable;
}
?>

this should do what you like :)

ram obrero
  • 197
  • 10