murphyz
11-24-2003, 09:46 PM
Hello,
I have some javascript for use within a php page.
The script is supposed to display one of two images (in two instance) depending on certain criteria.
1st) If the user is logged out, display an image called 'icon_mini_login.gif', and if they are logged in, show 'icon_mini_login.gif'.
2nd) When logged in, if the user has no new private messages, show 'icon_mini_message.gif', and if they do have new messages show 'icon_mini_messages.gif.
The script is from another template where it works, and the only changes that have been made are with the image names. When I run the script, the page itself says there is an error (via status bar message) and that error is
Char: 2
'Error. 'document.images.navigate0' is null or not an object
The code is as follows, and I was hoping someone may be able to spot a glaringly obvious error I have missed.
<script language="JavaScript" type="text/javascript">
<!--
//declaring variables and arrays
var privmsg_image_path = "{PRIVMSG_IMG}", current_lang = "";
//extract the current language string
current_lang = privmsg_image_path.match(/lang_[a-z]*/);
if (current_lang != ""){
<!-- BEGIN switch_user_logged_out -->
//assign image paths
document.images["navigate0"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_faq.gif"; //faq
document.images["navigate1"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_login.gif"; //login/logout
document.images["navigate2"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_search.gif"; //search
document.images["navigate3"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_search.gif"; //profile
document.images["navigate4"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_members.gif"; //memberlist
document.images["navigate5"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_groups.gif"; //usergroups
document.images["navigate6"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_message.gif"; //private messages/new private messages
document.images["navigate7"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_register.gif"; //register
<!-- END switch_user_logged_out -->
<!-- BEGIN switch_user_logged_in -->
//parse strings
loginlogout = "{U_LOGIN_LOGOUT}";
stringIndex = loginlogout.indexOf("amp");
loginlogout2 = loginlogout.slice(0,stringIndex);
loginlogout2 += loginlogout.slice(stringIndex+4);
//assign image paths
document.images["navigate0"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_faq.gif"; //faq
document.images["navigate1"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_logout.gif"; //login/logout
document.images["navigate2"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_search.gif"; //search
document.images["navigate3"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_profile.gif"; //profile
document.images["navigate4"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_members.gif"; //memberlist
document.images["navigate5"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_groups.gif"; //usergroups
document.images["navigate6"].src = "{PRIVMSG_IMG}"; //private messages/new private messages
document.images["navigate7"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_register.gif"; //register
<!-- END switch_user_logged_in -->
}
//-->
</script>
I have changed the name of all images involved to match that of the code.
Also, this part of the code:
document.images["navigate6"].src = "{PRIVMSG_IMG}";
takes the information from a .cfg file that basically just names the two images involved.
Thanks in advance if anyone can help, or suggest an easier way to do this.
Mxx
I have some javascript for use within a php page.
The script is supposed to display one of two images (in two instance) depending on certain criteria.
1st) If the user is logged out, display an image called 'icon_mini_login.gif', and if they are logged in, show 'icon_mini_login.gif'.
2nd) When logged in, if the user has no new private messages, show 'icon_mini_message.gif', and if they do have new messages show 'icon_mini_messages.gif.
The script is from another template where it works, and the only changes that have been made are with the image names. When I run the script, the page itself says there is an error (via status bar message) and that error is
Char: 2
'Error. 'document.images.navigate0' is null or not an object
The code is as follows, and I was hoping someone may be able to spot a glaringly obvious error I have missed.
<script language="JavaScript" type="text/javascript">
<!--
//declaring variables and arrays
var privmsg_image_path = "{PRIVMSG_IMG}", current_lang = "";
//extract the current language string
current_lang = privmsg_image_path.match(/lang_[a-z]*/);
if (current_lang != ""){
<!-- BEGIN switch_user_logged_out -->
//assign image paths
document.images["navigate0"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_faq.gif"; //faq
document.images["navigate1"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_login.gif"; //login/logout
document.images["navigate2"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_search.gif"; //search
document.images["navigate3"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_search.gif"; //profile
document.images["navigate4"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_members.gif"; //memberlist
document.images["navigate5"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_groups.gif"; //usergroups
document.images["navigate6"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_message.gif"; //private messages/new private messages
document.images["navigate7"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_register.gif"; //register
<!-- END switch_user_logged_out -->
<!-- BEGIN switch_user_logged_in -->
//parse strings
loginlogout = "{U_LOGIN_LOGOUT}";
stringIndex = loginlogout.indexOf("amp");
loginlogout2 = loginlogout.slice(0,stringIndex);
loginlogout2 += loginlogout.slice(stringIndex+4);
//assign image paths
document.images["navigate0"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_faq.gif"; //faq
document.images["navigate1"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_logout.gif"; //login/logout
document.images["navigate2"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_search.gif"; //search
document.images["navigate3"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_profile.gif"; //profile
document.images["navigate4"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_members.gif"; //memberlist
document.images["navigate5"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_groups.gif"; //usergroups
document.images["navigate6"].src = "{PRIVMSG_IMG}"; //private messages/new private messages
document.images["navigate7"].src = "templates/cowandchicken/images/" + current_lang + "/icon_mini_register.gif"; //register
<!-- END switch_user_logged_in -->
}
//-->
</script>
I have changed the name of all images involved to match that of the code.
Also, this part of the code:
document.images["navigate6"].src = "{PRIVMSG_IMG}";
takes the information from a .cfg file that basically just names the two images involved.
Thanks in advance if anyone can help, or suggest an easier way to do this.
Mxx