|
-
Jun 1st, 2005, 10:58 AM
#1
Thread Starter
Addicted Member
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
Thanks, BIOSTALL
-
Jun 1st, 2005, 11:20 AM
#2
Frenzied Member
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
If I have been helpful please rate my post. If I haven't tell me!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|