| | |
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 |
Tag cloud for PHP
.htaccess access ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl database date delete directory display download dynamic echo email error file files folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu mlm mod_rewrite multiple mysql navigation oop parse parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms soap source space sql structure syntax system table trouble tutorial update upload url validation validator variable video web xml youtube






