is it possible to alert session variable.is the syntax is correct...

<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
function login()
{
alert($_SESSION["un"]);
}
-->
</SCRIPT>
</head>
<body bgcolor="#f1f3f3"> 
<form>
<?php
print "<input type='submit' value='submit' onClick='javascript:login();'>";
?>
</form>
</body>
</html>

It is possible. But you can do it this way.

<script type='text/javascript'>
alert(<?php echo $_SESSION['un']; ?>);
</script>

If that doesn't work, try, alert('<?php echo $_SESSION['un']; ?>'); Cheers,
Naveen

thank u for ur reply.i tried both methods.BUT output is empty message box.there is no value displayed in message box.

<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
function login()
{
alert(<?php echo $_SESSION["un"]; ?>);
}
-->
</SCRIPT>
</head>
<body bgcolor="#f1f3f3"> 
<form>
<?php
$g=hi;
$_SESSION["un"]=$g;
print "<input type='submit' value='submit' onClick='javascript:login();'>";
?>
</form>
</body>
</html>
<?php
session_start();
?>
<html>
<head>
<script type="text/javascript">
function login() {
	alert('<?php echo $_SESSION['un']; ?>');
}
</script>
</head>
<body bgcolor="#f1f3f3">
<form method="post" onsubmit="javascript:login();">
<?php
$g=hi;
$_SESSION["un"]=$g;
?>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

Try this. Btw, you didn't have session_start in your script.

I got your PM. I couldn't reply you back cuz maybe you have disabled PM. Anyways, good luck !

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.