hi
how to alert a session variable in javascript function

Recommended Answers

All 4 Replies

<?php
session_start();
$_SESSION['user']="test";
echo "<script type='text/javascript'>alert('".$_SESSION['user']."');</script>";
?>

Like this ?

<script language="javascript">
       function addmanips(){ 
         var nW = window.open('add_qualifica.php?seeker_id=<? echo $_SESSION["seekerid"]?>&action=new','AddQualification','width=640,height=480,menubar=no,status=no,location=no,toolbar=no,scrollbars=no'); 
       	 nW=null;
	   } 	
	</script>

its not working.....

<?php
session_start();
$_SESSION['seekerid']="test";
?>
<html>
<head>
<script type="text/javascript">
      function addmanips(){ 
         var nW = window.open('add_qualifica.php?seeker_id=<? echo $_SESSION["seekerid"]; ?>&action=new','AddQualification','width=640,height=480,menubar=no,status=no,location=no,toolbar=no,scrollbars=no'); 
       	 nW=null;
	   } 	
	</script>
	</head>
	<body onload='addmanips();'>
</body>
</html>

this works for me!

In the ops last post, they neglected a semicolon <? echo $_SESSION["seekerid"]?> should have been <? echo $_SESSION['seekerid']; ?> as illustrated in your response.

However as a word of advice, php short tags should be avoided as there is no guarantee that they are enabled if you were to move your code to a new server.

Also if you are going to use short tags <?=$_SESSION['seekerid']?> is a cleaner approach. but ONLY works with short tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.