Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic form validation with ASP variables

I have 52 members in my database. When displayed in the admin panel, each one has a form associated with it so I can make notes for each member.

Each Member has an ID so I name each form on the page like this: "frmRepNotes<%=MemberList("MemberID")%>" based on the memberID from the database. This results in something like frmRepNotes67453. I now want to validate the form before saving the notes.

How can I use that number in the JavaScript?

function validate(strid)
{
     var ErrorFound = 0
     if (document.'+strid+'.taNotes.value == '')
     {
          ErrorFound = ErrorFound + 1
     }
     if (ErrorFound == 0)
     {
          document.'+strid+'.submit();
     }
}

How can this be done?

like image 423
neojakey Avatar asked Jun 10 '26 10:06

neojakey


1 Answers

Consider refactoring to be something like this?

function validate(strid)
{     
    var ErrorFound = 0; 
    var theForm = document.getElementById("frmRepNotes"+strid);     
    if (theForm.taNotes.value == '')     
    {          
        ErrorFound +=1;     
    }     
    if (ErrorFound == 0)     
    {          
        theForm.submit();     
    }
}
like image 200
p.campbell Avatar answered Jun 11 '26 23:06

p.campbell