Javascript two functions 'onclick'
hey,
i have a form with 7 texboxes. i then have two functions; one to check if two of the textboxes have the same value and one to check if any of the textboxes are blank.
Heres the first one:
Code:
function compare(val1, val2) {
if (val1 != val2) {
alert("Your passwords do not match");
return false;
}else{
return true;
}}
Heres the second one:
Code:
function checkempty() {
var abc, bcd, cde, def, efg, fgh, ghi
abc = document.getElementById('username');
bcd = document.getElementById('password');
cde = document.getElementById('passwordconfirm');
def = document.getElementById('emailaddress');
efg = document.getElementById('location');
fgh = document.getElementById('secretquestion');
ghi = document.getElementById('secretanswer');
if (abc.value == ''||bcd.value == ''||cde.value == ''||def.value == ''||efg.value == ''||fgh.value == ''||ghi.value == '') {
alert("Not all fields contain data");
return false;
}else{
return true;
}}
Now, i then call the two functions in the 'onclick' event of the submit button by doing:
Code:
onClick="return compare(form1.password.value,form1.passwordconfirm.value); return checkempty();"
The only thing is, only the first function is working. If there are blank textboxes the form will still submit. Can anyone see anything wrong with this as i'm tearing my hair out over it :cry:
Thanks, BIOSTALL
Re: Javascript two functions 'onclick'
You can only have one return statement.
Try creating a new function and call that in the onclick event:
Code:
function validate(val1, val2) {
if (compare(val1, val2) && checkempty()) {
return true;
} else {
return false;
}
}
HTH
DJ