View Single Post
  #1 (permalink)  
Old June 15th, 2006, 07:55 AM
Lucy Lucy is offline
Authorized User
Join Date: Jul 2003
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Looping through a step in my form validation

Hi there

I was wondering if someone could help with the following problem...

I have some javascript that validates a form before it submits to a process page.

It goes something like this:

function processForm(form)
    var message = "Please:\n";
    var badFlag = false;

    if (form.elements['content_title'].value == "")
        message = message + "Enter Title.\n";
        badFlag = true;

    if ((!form.elements['content_image2'].value == "") && (form.elements['content_image2_align'].value == ""))
        message += "Choose whether to align image 2 to the left or right of your text.\n";
        badFlag = true;

    if(badFlag == true){
        return false;
    return true;

This all works fine BUT I have up to 8 possible fields in my form which run from content_image2 to content_image8 so I thought i'd put this section of code in a for loop and wrote the following...

    for (var i=2;i<=8;i=i++)
        if ((!form.elements['content_image' + i].value == "") && (form.elements['content_image' + i + '_align'].value == ""))
        message += "Choose whether to align image" + i + " to the left or right of your text.\n";
        badFlag = true;

BUT it crashes my browser!!

I haven't done much javascript programming so I don't know what i'm doing wrong so any help would be greatly appreciated. I guess I could do it the really long way but thought this would be a better solution!

Thanks in advance

Lucy xx
Reply With Quote