...

View Full Version : Elements not found in Firefox, works well with IE



bashdrew
12-21-2006, 06:57 AM
Hi,


I have here a piece of my code. This code is supposed to change a password. It works well with IE but just can't find the elements in Firefox. I have already tried using getElementById() but having same results. Does anyone know of any workaround? Thanks.


Regards,
Andrew


<html lang="en">
<head>
<title>change password</title>

<script language="JavaScript">
<!--


var messageIndex = 0;
var errorMessage = '';
var messagesArray = new Array();

function showMessages() {

if (messageIndex > 0) {
for (j = 0; j < messageIndex; j++) {
errorMessage += messagesArray[j] + '\n';
}
alert(errorMessage);
return false;
}
}


-->
</script>

<script language="JavaScript">
<!--

var bStay=false;
var aHelp;
var aFields;
var iWidth;
var sWidth;
var sOption;
var sHtml;
var i,iX,iY,iClX,iClY;
var JQPrompt="";
var inputType;
var fieldName;
var inputType1;
var fieldName1;
var strAction;
var status="";

function processData()
{
var i;
idHelp.style.visibility='hidden';

_changePassword();
}

function JQPopOut()
{
if (!bStay) idHelp.style.visibility="hidden";
}
document.write('<span style="visibility:hidden;" id="idHelp"> </span>');


function JQPopUpPrompt()
{
var param;

var counter;
var value1;
var value2;

sHtml=
'<table cellpadding="0" cellspacing="0" align="center">' +
'<tr><td>'+
'<form name="frmJQ" id="idJQ">';

sHtml+=
'<tr><td>new password</font></td><td><input type="password" name="newPassword" size="20" class="textbox" value=""></td></tr>' +
'<tr><td>confirm password</font></td><td><input type="password" name="conPassword" size="20" class="textbox" value=""></td></tr>';

sHtml+=
'<tr align="center"><td colspan="6"><table cellspacing="2" align="center"><tr align="center"><td><button name="cmdOK" class="buttonPopup" onClick="JQPrompt=document.forms.frmJQ; processData(); return false;">Ok</button></td>' +
'<td><button name="cmdCancel" class="buttonPopup" onClick="idHelp.style.visibility=\'hidden\'; bStay=false;">Cancel</button>' +
'</td></tr></table></td></tr></form></tr></table>';
idHelp.innerHTML=sHtml;

iClX=330;
iClY=150;
iX = document.body.clientWidth - iClX;
iY = document.body.clientHeight - iClY;
if ( iX < idHelp.offsetWidth)
idHelp.style.left = document.body.scrollLeft + iClX - idHelp.offsetWidth;
else
idHelp.style.left = document.body.scrollLeft + iClX;

if (iY < idHelp.offsetHeight)
idHelp.style.top = document.body.scrollTop + iClY - idHelp.offsetHeight;
else
idHelp.style.top = document.body.scrollTop + iClY;
idHelp.style.visibility="visible";
idHelp.style.position="absolute";

}
//-->
</script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--SCRIPT language="JavaScript" src="../includes/pos.js"></SCRIPT-->
<script type="text/javascript" language="javascript1.3"><!--
page = 'subscriberDetails.html';
//-->
</script>
<SCRIPT language="JavaScript" type="text/JavaScript">
<!-- BEGIN
function addGroup(group)
{
document.getElementById("groups").innerHTML += "<input name=\"groups\" type=\"hidden\" value=\""+group+"\">";
}
function addType(type)
{
document.getElementById("groups").innerHTML += "<input name=\"types\" type=\"hidden\" value=\""+type+"\">";
}
function changePassword()
{
JQPopUpPrompt();
}
function _changePassword()
{
var msg;
var userId;

for (i=0; i<JQPrompt.length; i++)
{
if (JQPrompt[i].name == "newPassword")
{
document.subscriberDetailsForm.newPassword.value=JQPrompt[i].value;
}
else if (JQPrompt[i].name == "conPassword")
{
document.subscriberDetailsForm.conPassword.value=JQPrompt[i].value;
}
}
msg="";
if (document.subscriberDetailsForm.newPassword.value == "" || document.subscriberDetailsForm.newPassword.value == null)
{
msg = "New Password is required.";
}
else if (document.subscriberDetailsForm.conPassword.value == "" || document.subscriberDetailsForm.conPassword.value == null)
{
msg = "Confirm Password is required.";
}
else if (document.subscriberDetailsForm.newPassword.value != document.subscriberDetailsForm.conPassword.value)
{
msg="Password Mismatch. Please try again.";
}
else if (document.subscriberDetailsForm.newPassword.value.length < 6 || document.subscriberDetailsForm.conPassword.value.length < 6)
{
msg="Password cannot be less than 6 characters.";
}
else if (document.subscriberDetailsForm.newPassword.value.length > 18 || document.subscriberDetailsForm.conPassword.value.length > 18)
{
msg="Password cannot be more than 18 characters.";
}

if (msg != "")
{
alert(msg);
}
else
{
document.subscriberDetailsForm.msisdn.value=document.subscriberDetailsForm.msisdn.value;
document.subscriberDetailsForm.userId.value=document.subscriberDetailsForm.userId.value;
document.subscriberDetailsForm.newPassword.value=document.subscriberDetailsForm.newPassword.value;
document.subscriberDetailsForm.action.value = "changepassword";
document.subscriberDetailsForm.submit();
}
}
// End -->
</SCRIPT>
<script type="text/javascript" language="javascript">
<!--
//-->
</script>
</head>
<body onload="showMessages();">
<form name="subscriberDetailsForm" method="post" action="/simplicate2.1/subscriberDetails.do">

<input type="hidden" name="action" value="details"></input>
<input type="hidden" name="conPassword"/>
<input type="hidden" name="newPassword"/>


<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
<input type="button" name="btnSubmit" value="Change Password" onclick="javascript:changePassword();" class="button"/>
</td>

</tr>
</table>


</form>
</body>

</html>

david_kw
12-21-2006, 07:38 AM
Just FYI, IE gives me an error if I try to change the password. It says

document.subscriberDetailsForm.msisdn

is not an object.

But I must admit your code is a bit confusing to me. For example, is this supposed to do anything?



document.subscriberDetailsForm.msisdn.value=document.subscriberDetailsForm.msisdn.value;
document.subscriberDetailsForm.userId.value=document.subscriberDetailsForm.userId.value;
document.subscriberDetailsForm.newPassword.value=document.subscriberDetailsForm.newPassword.value;


I'll look for a bit more to see if I see something.

david_kw

david_kw
12-21-2006, 07:45 AM
Ok I made 2 changes and I don't know if it works but it doesn't give errors anymore.

The first was to comment the 3 lines of code out that I mentioned in my previous post. This fixed the fact that msisdn isn't in the form and unless I'm missing something those lines didn't seem to do anything anyway.

The second was to change your dynamic html to



sHtml=
'<form name="frmJQ" id="idJQ">'+
'<table cellpadding="0" cellspacing="0" align="center">' +
'<tr><td>';

sHtml+=
'<tr><td>new password</font></td><td><input type="password" name="newPassword" size="20" class="textbox" value=""></td></tr>' +
'<tr><td>confirm password</font></td><td><input type="password" name="conPassword" size="20" class="textbox" value=""></td></tr>';

sHtml+=
'<tr align="center"><td colspan="6"><table cellspacing="2" align="center"><tr align="center"><td><button name="cmdOK" class="buttonPopup" onClick="JQPrompt=document.forms.frmJQ; processData(); return false;">Ok</button></td>' +
'<td><button name="cmdCancel" class="buttonPopup" onClick="idHelp.style.visibility=\'hidden\'; bStay=false;">Cancel</button>' +
'</td></tr></table></td></tr></tr></table></form>';
idHelp.innerHTML=sHtml;


The only change I made (on purpose) was to move the <form> tag outside the outer <table> instead of in it. I think what you were seeing in FF was caused by this. It appears that FF was upset that you didn't close the <form> tag within the <td> so decided to throw it's own </form> tag in. That left all the inputs outside the form element so unaddressable. That is why it kept giving the error.

Hopefully that helps.

david_kw

bashdrew
01-04-2007, 07:53 AM
Hi,


Wow, it works well now. Thanks so much. It was really a big help for me. Thanks again.



Regards,
Andrew



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum