Mike said:
Thomas said:
Mike wrote:
:
Mike wrote:
I have 2 functions:
One checks that 2 password fields have the same value and one runs
the form fields though some AJax to a php file.
OnSubmit never seems to run:
<form name="Acct" onSubmit="process(Email.value,Password.value)">
onSubmit="return process(Email.value,Password.value)"
forget about the onclick
[...]
What about validatePw?
You can call it before process(), or process() can call it. [...]
Can you do an onSubmit and an onClick?
In a sense, yes.
Does one take precedence?
I beg your pardon?
<form ... onsubmit="...">
...
<input type="submit" ...>
...
</form>
See also <
http://www.w3.org/TR/html401/interact/forms.html#edef-INPUT>.
Please trim your quotes to the relevant minimum:
<
http://jibbering.com/faq/#posting> pp.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <
[email protected]>- Hide quoted text -
- Show quoted text -
I still dont understand why this doesnt work:I'd like an explanation.
MAIN FILE
<script src="CheckEmailaddress.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Russ Swift (
[email protected]) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!!
http://javascript.internet.com -->
<!-- Begin
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.Acct.Password.value;
alert (document.Acct.Password.value);
var pw2 = document.Acct.Password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.Acct.Password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters
long. Try again.');
return false;
}
// check for spaces
if (document.Acct.Password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter
your password.");
return false;
}
else {
alert('Nice job.');
return true;
}
}
}
// End -->
</script>
</head>
<body>
<table width="500" border="1px" align="center" cellpadding="0"
cellspacing="0" id="mainOne">
<tr>
<td>
<form name="Acct" onsubmit="process(Email.value,Password.value)">
<p class="LoginFont">
E-mail <input type="text" name="Email" id="Email" size="30"
value="a"/> said:
<DIV ID="email_result"> </DIV>
Password <input name="Password" id="password1" size="30"
type="password" value="aaaaaa" /><br />
Password Again <input name="Password2" id="password2" size="30"
type="password" value="aaaaaa" /><br />
<DIV ID="password_result"> </DIV>
</p>
<label>
<input type="submit" name="LoginButton" id="LoginButton"
value="Login" /></form>
<div id="ttHint"></div>
</td>
</tr>
</table>
</body>
</html>
CHECKEMAILADDRESS.JS
var xmlHttp;
var a;
var b;
function process(a,b)
{ alert ("help1");
if(validatePwd())
{
alert ("help2");
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return
}
var url="CheckEmailAddress.php";
url=url+"?Email="+a+"&Password="+b;
alert(url);
xmlHttp.open("GET",url,true);
alert ("help3");
xmlHttp.send(null);
alert ("help4");
xmlHttp.onreadystatechange=stateChanged;
}
function stateChanged()
{
alert(xmlHttp.readyState)
if (xmlHttp.readyState==4)
{
if (xmlHttp.responseText == "<p>This Username or E-mail address is
Already registered</p>")
{
document.getElementById("ttHint").innerHTML=xmlHttp.responseText;
}
else{
var emailurl="";
var emailurl = "CreateNewUserEmail.php"
emailurl=(emailurl+"?Email="+document.Acct.Email.value
+"&Password="+document.Acct.Password.value);
alert ("The URL is "+emailurl);
window.location = emailurl
}
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
} }
BUT THIS VERSION OF THE MAIN FILE DOES:
<script src="CheckEmailaddress.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Russ Swift (
[email protected]) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!!
http://javascript.internet.com -->
<!-- Begin
function validatePwd() {
var invalid = " "; // Invalid character is a space
var minLength = 6; // Minimum length
var pw1 = document.Acct.Password.value;
alert (document.Acct.Password.value);
var pw2 = document.Acct.Password2.value;
// check for a value in both fields.
if (pw1 == '' || pw2 == '') {
alert('Please enter your password twice.');
return false;
}
// check for minimum length
if (document.Acct.Password.value.length < minLength) {
alert('Your password must be at least ' + minLength + ' characters
long. Try again.');
return false;
}
// check for spaces
if (document.Acct.Password.value.indexOf(invalid) > -1) {
alert("Sorry, spaces are not allowed.");
return false;
}
else {
if (pw1 != pw2) {
alert ("You did not enter the same new password twice. Please re-enter
your password.");
return false;
}
else {
alert('Nice job.');
return true;
}
}
}
// End -->
</script>
</head>
<body>
<table width="500" border="1px" align="center" cellpadding="0"
cellspacing="0" id="mainOne">
<tr>
<td>
<form name="Acct" onSubmit="validatePwd()">
<p class="LoginFont">
E-mail said:
<DIV ID="email_result"> </DIV>
Password <input name="Password" id="password1" size="30"
type="password" /><br />
Password Again <input name="Password2" id="password2" size="30"
type="password" /><br />
<DIV ID="password_result"> </DIV>
</p>
<label>
<input type="button" name="LoginButton" id="LoginButton"
value="Login" onClick="process(Email.value,Password.value)" /></form>
<div id="ttHint"></div>
</td>
</tr>
</table>
</body>
</html>
Thnaks