Log in

View Full Version : php variables within javascript



liamallan
07-20-2011, 11:26 PM
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:

// 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

traq
07-21-2011, 03:47 AM
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? )

liamallan
07-21-2011, 07:36 AM
lol the ass() function displays 'blocks' on users profile like so...
http://shiftysplayground.co.uk/includes/profile.png

as u can see, i get a wrong path error once i press submit

traq
07-21-2011, 03:17 PM
"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.

liamallan
07-21-2011, 09:28 PM
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

traq
07-22-2011, 02:53 AM
1) please post the php code you are currently using.
2) please post the html/javascript markup it generates.