0

I have a PHP file in that I have declared a JavaScript variable.

I will get that variable value while I am opening the page directly by type the my URL on IE6.

But the problem is if I am clicking a href link to open the same page got particular variable undefined error on IE6.

After undefined error if I refresh the same page I can get the variable value.

I am using script tag to load the page

as like

<script language="javascript" src="commonjs.php"></script> 

In my commonjs.php

<?  include_once("myconffile.php");  ?>
var myvars = <?=$varConfValue['domainname']?>

Please help me on this.

3
  • 1
    Are you sure short_open_tag is enabled? Afaik, by default it is not. Commented Jan 6, 2012 at 9:53
  • yes its enabled and if i refresh the same page i can get the value for same variable after got the undefined error. Commented Jan 6, 2012 at 10:04
  • Are you sure you have cleaned the browser cache? Commented Jan 6, 2012 at 11:20

1 Answer 1

2

You should add quotes around the value of myvars if it is a string.

<?  include_once("myconffile.php");  ?>
 var myvars = "<?=$varConfValue['domainname']?>" 

Otherwise you get something like var myvars = localhost. Javascript then looks for a variable named localhost, which is undefined.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks naivists, In my original file i used quotes. Here i missed to mention it. please advise if any other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.