alert message for blank fields in a HTML form using java script function

sankusanku BeginnerLink Clerk
hai all,
i have a problem while submitting a form values from one page to another page using java script function,what happens is if all (or) any one of the field elements in form-1 is null or empty then the page shouldn't skip to next page.

i have written an alert message function for that but the alert message is working only when the first field element of form-1 is null, but if the other fields in that form element is null the alert message is not working and it simply skips on to the next page which i don't want it to happen.

coding for alert message is as follows:

function validate1()
{
for(i=0;i<=58;i++)
{
if(document.form1.elements.value == '')
{

alert ('shouldn\'t be null');
document.form1.srno.value=" ";
document.form1.srno.focus();
return false;
}
else
{
document.form1.action = '/../../filename';
}
}
}

in the above function the element represents elements in the html forms (i.e.,) textboxes,textareas etc.,
please give me a solution for this,

thanks in advance.

Comments

  • xPureNLxxPureNLx Moderator The Royal RAM
    No offense, but wouldn't it be handy to introduce yourself first? It's a non-written rule at many forums...

    Well, I'm no script pro, esspecially when it comes down to Jscript.

    Little suggestions:
    if(document.form1.elements.value == '')
    document.form1.srno.value=" ";

    You're using two different things (' and ") for the same type of value. I'd say: re-read your script and make sure it's basics are okay...

    Sorry I can't help you more...
    signaru02am7.jpg
    [B]MSN: xPureNLx@gmail.com[/B]
    
Sign In or Register to comment.