Forum Moderators: open
Help much appreciated!
<script type="text/javascript">
function validate(f){
if((f.telephone.value.length<1)&&(f.daytime.value.length<1)&&(f.mobile.value.length<1)){
alert('Please fill at least one phone no');
return false;
}
}
</script>
and
<script type="text/javascript">
function checkPw(form) {
email1 = form.email1.value;
email2 = form.email2.value;
if (email1!= email2) {
alert ("\nYou did not enter the same email address twice. Please re-enter your email address.")
return false;
}
else return true;
}
</script>
[pre]
String.prototype.trim = function(){ return this.replace(/^\s+/,'').replace(/\s+$/,''); }function validate(f)
{
var complete = true
var message = ''
if(
!f.telephone.value.trim() &&
!f.daytime.value.trim() &&
!f.mobile.value.trim()
)
{
message [red]+[/red]= 'Please fill at least one phone no\n\n'
complete = false;
}
if(f.email1.value.trim()!=f.email2.value.trim())
{
message [red]+[/red]= 'You did not enter the same email address twice.\nPlease re-enter your email address.'
complete = false
}
if(!complete)
alert(message)
return complete;
}
[/pre]
I have included a String::trim method. Might as well remove whitespace.
complete is true unless set to false. At the bottom, if
false, the alert is done, and false is returned, if true, the alert isn't done, and true is returned. So.. [pre]
if(!complete)
alert(message)[red];[/red]
return complete;
[/pre] [pre]
if(!complete) {
alert(message)
return false }
}
return true
[/pre] I think that the problem was that I was lazy, and left out the ;
- and copy'n'paste removed the line break.