/    Sign up×
Community /Pin to ProfileBookmark

Compatibility with Mozilla Help

Hello,

I am having difficulty getting my code to perform in Mozilla. I searched Google and tried to find where I have made my mistakes but I couldn’t find mucht–it seems. Can someone help me identify where I went wrong in getting my link to login to function correctly in Mozilla?

This is the call for the JavaScript in the HTML:

[code]
<td valign=”top”><p><script language=”JavaScript”>
BuildPanel();
</script></td>
[/code]

This is the JavaScript being called in my scripts folder:

[code]
var successpage = “account.htm”;
var loginpage = “index.htm”;

var imgSubmit = “graphics/bullet.gif”;
var imgReset = “graphics/bullet.gif”;

var users = new Array();

users[0] = new Array(“ndgadmin”,”password”,”account.htm”);

function login(username,password){
var member = null;
var loggedin = 0;
var members = users.length;
for(x=0;x<members && !loggedin; x++){
if((username==users[x][0])&&(password==users[x][1])){
loggedin = 1;
member = x;
break;
}
}

if(loggedin==1){
if(users[member][2] != “”) {
successpage = users[member][2];
}
setCookie(“login”,1);
if (top.location.href != location.href){
location.href = successpage;
}else{
top.location.href = successpage;
}
}else{
alert(‘Access denied. Please contact [email protected] ‘);
}
}

function logout() {
deleteCookie(“login”);
if (top.location.href != location.href){
location.href = loginpage;
}else{
top.location.href = loginpage;
}
}

var ckTemp = document.cookie;

function setCookie(name, value) {
if (value != null && value != “”)
document.cookie=name + “=” + escape(value) + “;”;
ckTemp = document.cookie;
}

function deleteCookie(name) {
if (getCookie(name)) {
document.cookie = name + “=” +
“; expires=Thu, 01-Jan-70 00:00:01 GMT”;
}
}

function getCookie(name) {
var index = ckTemp.indexOf(name + “=”);
if(index == -1) return null;
index = ckTemp.indexOf(“=”, index) + 1;
var endstr = ckTemp.indexOf(“;”, index);
if (endstr == -1) endstr = ckTemp.length;
return unescape(ckTemp.substring(index, endstr));
}

function checkCookie() {
var temp = getCookie(“login”);
if(!temp==1) {
alert(‘access denied’);
if(top.location.href != location.href){
location.href = loginpage;
}else{
top.location.href = loginpage;
}
}
}

function BuildPanel() {
document.write(‘<form name=”logon”><table align=”left” border=”0″><tr><td align=”right”>’);
document.write(‘<small><font face=”Verdana”>Username:</font></small></td>’);
document.write(‘<td><small><font face=”Verdana”><input type=”text” class=”textbox1″ name=”username” size=”20″></font></small>’);
document.write(‘<td align=”right”><small><font face=”Verdana”>Password:</font></small>’);
document.write(‘<small><font face=”Verdana”><input type=”password” class=”textbox1″ name=”password” size=”20″></font></small></td></tr>’);
if(imgSubmit == “”){
document.write(‘<tr><td align=”center” colspan=”2″><p><input type=”button” value=”Logon” name=”Logon” onclick=”login(username.value,password.value)”>’);
} else {
document.write(‘<tr><td align=”center” colspan=”2″><p><input type=”image” src=”‘+imgSubmit+'” name=”Logon” onclick=”login(username.value,password.value)”><small><font face=”Verdana”><a href=”#” name=”Logon” onclick=”login[username.value,password.value]”>Login</font></small></a>’);
}
if(imgReset == “”){
document.write(‘<input type=”reset” value=”Reset” name=”Reset”>’);
} else {
document.write(‘<input type=”image” src=”‘+imgReset+'” name=”Reset” onclick=”logon.reset();”><small><font face=”Verdana”><a href=”#” name=”Reset” onclick=”logon.reset();”>Reset</a></font></small>’);
}
document.write(‘</p></td></tr></table></form>’);
}

[/code]

This is a working demo of the files:

[url]http://www.mymonkeyisland.com[/url]

Any help or point in the right direction would be appreciated. This code works in Explorer 7+ and –

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJun 07.2007 — I think these bits of code could be the trip up:
login(username.value,password.value)
On the onclick event of a button, the onclick event is executed in the scope of the clicked button. Do you have global JavaScript variables called username and password, or are you trying to access the values in the username and password text fields. Try this code instead:
login(this.form.elements['username'].value, this.form.elements['password'].value)
Standards compliant browsers, of which Internet Explorer 5+ is fairly compliant, do not create references to form fields in the way you appeared to use them. All form fields and buttons contain a property called .form, which is a reference to the FORM tag. And each FORM tag contains a property called .elements, which is an integer based array, and associative array containing references to all the form fields.

That's why in the onclick event, you can use:
<i>
</i>this.form.elements['field_name'].value
1. 2. 3. 4.


  • 1. The 'this' keyword in the onclick event refers to the button that was clicked.


  • 2. The this.form property is a reference to the FORM the button is in.


  • 3. The .elements property of the FORM is a list of references to all form fields.


  • 4. The name of a field can then be used in array-notation to access that DOM node. Note that if you have more than one form field with that name, *.elements['field_name'] will be an array-like list of DOM nodes.
  • Copy linkTweet thisAlerts:
    @maxmmizeauthorJun 07.2007 — onclick="login(Logon.logon.elements['username'].value, Logon.logon.elements['password'].value)

    Ok, I'm starting to get what you are doing--especially using [] instead of (). I researched and found out that Mozilla likes []. WHere am I still going wrong?
    Copy linkTweet thisAlerts:
    @toicontienJun 07.2007 — No clue. ? Are you getting a JavaScript error? You're not saying what the problem is. Can you be more descriptive?
    ×

    Success!

    Help @maxmmize spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...