| | |
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: \ stuff
- Next Thread: Adding Discount
Views: 3276 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube






