| | |
pass variable from php to javascript
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 183
Reputation:
Solved Threads: 5
hi
i want to pass variable from php to javascript.i want to pass my group[name please tell me.the current code is not working
javascript code
i want to pass variable from php to javascript.i want to pass my group[name please tell me.the current code is not working
PHP Syntax (Toggle Plain Text)
<? session_start(); require_once('common/dblayer.php'); $db=new dblayer(); $id=$employer_id; $empid=$db->getgroupname($id); $groupname=$empid[0]["group1"]; echo $groupname; ?>
PHP Syntax (Toggle Plain Text)
//Contents for menu 1 var menu1=new Array() menu1[0]='<a href="employercp.php">Job Portal</a>' menu1[1]='<a href="cggroup.php?id=<? echo $groupname; ?>">Groups</a>'
try:
javascript Syntax (Toggle Plain Text)
var d=document.form1; var v=d.inputname.value; alert(v);
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Nov 2007
Posts: 183
Reputation:
Solved Threads: 5
this is actually a menu .i have included in all the pages.
PHP Syntax (Toggle Plain Text)
<? session_start(); require_once('common/dblayer.php'); $db=new dblayer(); $id=$employer_id; $empid=$db->getgroupname($id); $groupname=$empid[0]["group1"]; echo $groupname; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> var menu1=new Array() menu1[0]='<a href="employercp.php">Job Portal</a>' menu1[1]='<a href="cggroup.php?id=<?php echo $groupname; ?>">Groups</a>' </script> </head>
Are you sure it isn't working ? This code with slight modification to yours is working.
I believe $groupname is empty in your case.
php Syntax (Toggle Plain Text)
<?php session_start(); $groupname = "test"; echo $groupname; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> var menu1=new Array() menu1[0]='<a href="employercp.php">Job Portal</a>' menu1[1]='<a href="cggroup.php?id=<?php echo $groupname; ?>">Groups</a>' document.write(menu1[0] + menu1[1]); </script>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- pass the javascript variable to php page (PHP)
- Pass Javascript variable to PHP code (PHP)
- Pass a javascript variable to PHP in the same function (JavaScript / DHTML / AJAX)
- get html element value using php (PHP)
- Passing variables to and from PHP (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: detecting google
- Next Thread: [Urgent] Write excel cell values to SQL DB based on cell color?
| Thread Tools | Search this Thread |
# 5.2.10 access alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






