Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working only on 1st Condition

Status
Not open for further replies.

sciclunam

Programmer
Oct 12, 2002
138
MT
This function is working only if the first field beong check is left empty 'add.b_name', the others are being ingonored. Any idea why? I am not sure about the four } I have placed at the end, one for every if statement.

Thanks


function formCheck() {
var not_blank = true;
if (document.add.b_name.value.length < 3){
if (document.add.b_surname.value.length < 3){
if (document.add.g_name.value.length < 3){
if (document.add.g_surname.value.length < 3){
alert("Any of the required fields left blank or invalid");
not_blank = false;
}
return not_blank;
}}}}

Getting married in Malta?
Visit
 
There is something else, the others are not entirely being ignored, If I leave the first element empty but fill the second element no alert message is given. It looks like the if statements are like "AND" ie, if <condition> and <condition> etc...

I need an "OR" ie, If <condition> or <condition> etc...

Thanks

Getting married in Malta?
Visit
 
Code:
function formCheck()
{
  var f = document.forms['add'];
  if (f.elements['b_name'].value.length < 3 [red]||[/red] f.elements['b_surname'].value.length < 3 [red]||[/red] f.elements['g_name'].value.length < 3 [red]||[/red] f.elements['g_surname'].value.length < 3)
  {
    alert("Any of the required fields left blank or invalid");
    return false;
  }
  return true;
}

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top