Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Javascript - What is wrong with this expression?

I have the following snippit of an expression im making that i cannot get to work... its a function that is called onsubmit of a form.. note that the title and surname works, after that nothing

function checkit(_formname)

{

if (_formname.lsttitle.selectedIndex == 0)

{

alert ("Please select a title");

return false;

}

else if (_formname.txtsurname.value.length == 0 )

{

alert("Surname is empty!");

_formname.txtsurname.focus();

return false;

}

else if (checkone(_formname.txtsurname.value) != true)

{

alert("Surname is "+ _formname.txtsurname.value+" contains numbers - only uppercase and lowercase letters permitted");

_formname.txtsurname.focus();

return false;

}

else if (_formname.txtname.value.length == 0 )

{

alert("Name is empty!");

_formname.txtname.focus();

return false;

}

Update:

Sorry to say, but this is only a part of the code.... the code goes on to validate 10 different fields. Full code is:

function checkit(_formname)

{

if (_formname.lsttitle.selectedIndex == 0)

{

alert ("Please select a title");

return false;

}

else if (_formname.txtsurname.value.length == 0 )

{

alert("Surname is empty!");

_formname.txtsurname.focus();

return false;

}

else if (checkone(_formname.txtsurname.value) != true)

{

alert("Surname is "+ _formname.txtsurname.value+" contains numbers - only uppercase and lowercase letters permitted");

_formname.txtsurname.focus();

return false;

}

else if (_formname.txtname.value.length == 0 )

{

alert("Name is empty!");

_formname.txtname.focus();

return false;

}

else if (checkone(_formname.txtname.value) != true)

{

alert("Name is "+ _formname.txtName.value+" contains numbers - only uppercase and lowercase letters permitted");

_formname.txtname.f

3 Answers

Relevance
  • 9 years ago
    Favorite Answer

    Remove the else part of all the ifs. It is not needed as the return statement will terminate the function.

    Also check the spelling of the field txtname on the form. The name is case sensitive.

    Have fun.

  • Anonymous
    9 years ago

    Is checkone a previously declared function and what does it output?

    Try checking that.

  • David
    Lv 6
    9 years ago

    You left out a closing bracket on the bottom.

Still have questions? Get your answers by asking now.