Results 1 to 6 of 6

Thread: php variables within javascript

  1. #1
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default php variables within javascript

    hey, is it possible to use php variables in javascript? i been trying to create an admin notes section on my users profiles that only admin can see, and to make notes on each user.

    it works great, but i am unable to parse a php variable within the javascript, here is the code im using:
    PHP Code:
    // notes
    if (allow_access(3)) {
            
    $res sql_query("SELECT * FROM `".tb()."accounts` where id={$owner['id']}");
            
    $output '';
            while (
    $row sql_fetch_array($res)) {
            
                
    $f 1;
                
    $output '<script language="javascript" type="text/javascript" src="js/jeditable.js"></script>
                <script>
                $(document).ready(function() {
         
         $(\'.edit_area\').editable("index.php?p=u/'
    .$row['username'].'/savenote", { 
             type      : \'textarea\',
             cancel    : \'Cancel\',
             submit    : \'OK\',
           
         });
     });
     </script>
                
    <div class="edit_area" id="div_2">'
    .$row['notes'].'</div>';
            }
            
    ass(array('title'=>t('User Notes'), 'content' => $output));
            } 
    what it does, it displays plain text on the users profile, displaying notes on the user, and onclick of the plain text, it turns into a textarea with the notes pre-loaded, and once finished making notes, click submit and the form is submitted to another function for processing, but as u can see, i need to use a variable within the url to send for processing.

    can anyone advise?

    thanx
    Last edited by liamallan; 07-20-2011 at 11:32 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    are you receiving an error, or just missing output? are you sure you're getting a result from your query?

    (also, I'm almost afraid to ask, but what does your ass() function do? )

  3. #3
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    lol the ass() function displays 'blocks' on users profile like so...


    as u can see, i get a wrong path error once i press submit
    Last edited by liamallan; 07-21-2011 at 08:07 AM.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    "echo '$ownername' " is not in the code you posted above. are you sure this is where the error is coming from? it doesn't even really look like a php error. it might be a user-defined error message that your javascript is returning.

  5. #5
    Join Date
    Feb 2010
    Location
    Falkirk, Scotland
    Posts
    142
    Thanks
    21
    Thanked 4 Times in 4 Posts

    Default

    yea, it is different, just one of the many methods i have tried for the variable to echo a result. and u are correct, it is a user defined error message that tells me that the path to the function is incorrect, the path should display as u/Shifty/savenote, Shifty being my username. im also 110% sure thats where the problem lies

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    1) please post the php code you are currently using.
    2) please post the html/javascript markup it generates.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •