Click here to Skip to main content
15,917,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm very new to javascript. I have a trouble in changing the value of javascript global variable. Here is my code.

In header.php file I have declared the global variable.
XML
<script type="text/javascript">
        var name;

</script>

Then in index.php file I change the value of the "name" variable.
C#
if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                             {
                                                if(xmlhttp.responseText != null)
                                                    {
                                                 JSONObjList=xmlhttp.responseText;
                                                    if(JSONObjList!=null){
                                                         var JSONListObj = JSON.parse(JSONObjList);
                                                          if(JSONListObj.loggedIn == true){
//
                                                               name=JSONListObj.username+"|true";
                                                               alert(name);
                                                          }
                                                          else{
                                                              name="";
//                                                              logstatus="false";
                                                          }


                                                    }


                                                 window.location = "http://localhost/mvc/myplaylist";
                                                    }
                                                    else{
                                                  document.getElementById("myDiv").innerHTML="Login details are incorrect";
                                                  form.email.value="";
                                                  form.password.value="";
                                             }


Here alert(name) gives the required value. Then I want to access that value again in header.php as in the following.

XML
<script type="text/javascript">
                                             alert(name);
                               var arr=name.split("|");
                               if(arr != null)
                                   {

                                       var status=arr[1];
                                       var inputstr=arr[0];
                                   }
                               if(status =="true"){

                                       document.write("<td id='log' rowspan='2'onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage('Image4','','images/bttnn/btn_logout.png',1)' onclick='DestroySes()'><img src='images/bttnn/btn_logout_h.png' alt='Log Out' name='Image4' width='150' height='56' border='0'</td>");
                               }
                                else
                                      document.write("<td id='log' rowspan='2'><a href='#login_form' id='login_pop'onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage('Image4','','images/bttnn/btn_login.png',1)'><img src='images/bttnn/btn_login_h.png' alt='Log In' name='Image4' width='150' height='56' border='0'></a></td>");

                          </script>


Above code works fine for Chrome. But when I run it in Firefox name value prints nothing in header.php

Can anybody explain me the reason.
Posted
Comments
Shelby Robertson 19-Jun-12 10:16am    
I'm assuming header.php is included in index.php somewhere?

1 solution

the code is not working in firefox bcz this property is not supported by firefox but chrome supported.

Thanks
Nikhil
 
Share this answer
 
Comments
Richard MacCutchan 20-Jun-12 10:42am    
Please stop spamming the forum with these non-answers. They help no one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900