Click to See Complete Forum and Search --> : Help !!
raktims
01-09-2003, 12:00 PM
Hi I am new to javascript and web dev. In the following code I am trying to open a window to validate username & pwd. The window is opening but when the buttons are clicked nothing is happening. please advise.
Thanks,
Raktim.
<SCRIPT Language="JavaScript">
var writeWin = null;
var wd = null;
var writeWin = null;
function writeLeft()
{
writeWin = window.open('','aWin','top=0,left=0,width=350,height=350');
var ePen = '<html><head><title>Login</title></head>';
ePen += '<body text="#cccccc">';
ePen += '<Form name="logonForm" method="GET" onSubmit="return ValidateForm(this)">';
ePen += '<p align="left"><font color="#009999">Email</font> </p>';
ePen += '<INPUT TYPE=text NAME=email VALUE="" MAXLENGTH=60 SIZE=20>';
ePen += '<p align="left"><font color="#009999">Password</font> </p>';
ePen += '<INPUT TYPE=password NAME=passwd VALUE="" MAXLENGTH=60 SIZE=20>';
ePen += '<input type="submit" value="Submit" name="Submit">';
ePen += '<INPUT type="button" value=" Ok " name="Ok" onClick="VerifyLogin">';
ePen += '<INPUT type="button" value="Cancel" name="Cancel" onClick="Closewin()">';
ePen += '</form></body></html>';
wd = writeWin.document;
wd.open();
wd.write(ePen);
wd.close();
}
function Closewin ()
{
alert ("Cancel Clicked");
writeWin.close();
}
function VerifyLogin()
{
alert ("Submit Clicked");
}
function ValidateForm(form)
{
alert("In Here");
if ( (witeWin.document.form.passwd.value == "") || (witeWin.document.form.email.value == ""))
{
alert("Please fill in all required fields.");
return false;
}
if ((witeWin.document.form.passwd.value == "1234") && (witeWin.document.form.email.value == "raktim"))
{
return true;
}
}
//-->
</SCRIPT>
<html><head></head>
<body onload="JavaScript:writeLeft()">
</body>
</html>
khalidali63
01-09-2003, 12:13 PM
Well, what is it you want to do when these buttons are pressed.
because that will be required to post an answer for you.
Khalid
raktims
01-09-2003, 12:40 PM
I just need to capture the values from the 2 fields and validate it and then redirect them to another page.
Either of the 'ok' or'submit' button will do. How do I acheive that ?
Thanks for your help.
Raktim
AdamBrill
01-09-2003, 01:02 PM
I think this is what you want:
<html>
<head>
<SCRIPT Language="JavaScript">
var writeWin = null;
var wd = null;
var writeWin = null;
function writeLeft()
{
writeWin = window. open('','aWin','top=0,left=0,width=350,height=350'
);
var ePen = "<html><head><title>Login</title></head>";
ePen += "<body text='#cccccc'>";
ePen += "<Form name='logonForm' method='GET' onSubmit='return window.opener.ValidateForm(this,document.forms[0].passwd.value,document.forms[0].email.value)'>";
ePen += "<p align='left'><font color='#009999'>Email</font> </p>";
ePen += "<INPUT TYPE=text NAME=email VALUE='' MAXLENGTH=60 SIZE=20>";
ePen += "<p align='left'><font color='#009999'>Password</font> </p>";
ePen += "<INPUT TYPE='password' NAME=passwd VALUE='' MAXLENGTH=60 SIZE=20>";
ePen += "<input type='submit' value='Submit' name='Submit'>";
ePen += "<INPUT type='button' value=' Ok ' name='Ok' onClick='window.opener.VerifyLogin()'>";
ePen += "<INPUT type='button' value='Cancel' name='Cancel' onClick='window.opener.Closewin()'>";
ePen += "</form></body></html>";
wd = writeWin.document;
wd.open();
wd.write(ePen);
wd.close();
}
function Closewin ()
{
alert ("Cancel Clicked");
writeWin.close();
}
function VerifyLogin()
{
alert ("Submit Clicked");
}
function ValidateForm(form,pass,email)
{
alert("In Here");
if ( (pass == "") || (email == ""))
{
alert("Please fill in all required fields.");
return false;
}
if ((pass == "1234") && (email == "raktim"))
{
alert("return true");
return true;
}
else
{
return false;
}
}
//-->
</SCRIPT>
</head>
<body onload="JavaScript:writeLeft()">
</body>
</html>
Let me know if you have any more problems. BTW, if the window that opened the popup is closed, the popup will no longer function properly. So, you might want to try writing all of the functions to the popup... Let me know if you need help with that...
raktims
01-09-2003, 01:25 PM
Thanks a ton. that worked. You r correct I need to add the functions to the popup itself ? How should I proceed.
Also I am verifying the username etc in the pop and if verified I want to open another page in the PARENT window which created the popup. How can I do that ?
Thanks again.
Raktims.
AdamBrill
01-09-2003, 02:16 PM
Try this:
<html>
<head>
<SCRIPT Language="JavaScript">
var writeWin = null;
var wd = null;
var writeWin = null;
function writeLeft()
{
writeWin = window. open('','aWin','top=0,left=0,width=350,height=350'
);
var ePen = "<html><head><title>Login</title>";
ePen += "<script language=javascript>";
ePen += "function Closewin (){";
ePen += "alert ('Cancel Clicked');";
ePen += "writeWin.close();}";
ePen += "function VerifyLogin(){";
ePen += "alert ('Submit Clicked');}";
ePen += "function ValidateForm(form,pass,email){";
ePen += "alert('In Here');";
ePen += "if ( (pass == '') || (email == '')){"
ePen += "alert('Please fill in all required fields.');";
ePen += "return false;}";
ePen += "if ((pass == '1234') && (email == 'raktim')){";
ePen += "window.opener.location='http://www.yahoo.com';";
ePen += "window.close();"
ePen += "alert('return true');";
ePen += "return true;}";
ePen += "else{";
ePen += "return false;}";
ePen += "}";
ePen += "<\/script>";
ePen += "</head>";
ePen += "<body text='#cccccc'>";
ePen += "<Form name='logonForm' method='GET' onSubmit='return ValidateForm(this,document.forms[0].passwd.value,document.forms[0].email.value)'>";
ePen += "<p align='left'><font color='#009999'>Email</font> </p>";
ePen += "<INPUT TYPE=text NAME=email VALUE='' MAXLENGTH=60 SIZE=20>";
ePen += "<p align='left'><font color='#009999'>Password</font> </p>";
ePen += "<INPUT TYPE='password' NAME=passwd VALUE='' MAXLENGTH=60 SIZE=20>";
ePen += "<input type='submit' value='Submit' name='Submit'>";
ePen += "<INPUT type='button' value=' Ok ' name='Ok' onClick='VerifyLogin()'>";
ePen += "<INPUT type='button' value='Cancel' name='Cancel' onClick='Closewin()'>";
ePen += "</form></body></html>";
wd = writeWin.document;
wd.open();
wd.write(ePen);
wd.close();
}
//-->
</SCRIPT>
</head>
<body onload="JavaScript:writeLeft()">
</body>
</html>
Then in this line:
ePen += "window.opener.location='http://www.yahoo.com';";
Just change the link to where ever you want it to go if the Username and Password are correct. One thing, though, is the password isn't very secure. Anyone can view the source to find out what the username and password are. So, it may or may not work for what you want, but...
AdamBrill
01-09-2003, 04:30 PM
One more thing... If the password has to be more secure than that, you could use PHP. That is a LOT more secure than the javascript way. Just so you know...