Required fields


I've created a form, and I wish to use JSP to ensure that a user fills in all of my required fields... the code that I have at the moment works in IE, but when used in Firefox, it finds the unfilled fields but says they're "undefined" rather than telling me what fields they are (and therefore needs to be filled in)... can someone please help me? And maybe even suggest a better way to code it (since I know this code probably isn't the best or simplest way to do what I need)... Thank you! (see code below)

// JavaScript Document

    var reqfields = new Array();
    var intArrayCount = 0;

    function defineRequired(str)
                  reqfields = reqfields.concat (str.split(',')) ;
//                  displayArray();
       function requiredCheck(obj,str)
                  //alert (obj);
                  if (obj.checked) {
                        //alert (obj+" is checked") ;
                        defineRequired(str) ;
                        //alert (obj+" is unchecked");
                        scanArray(str) ;
      function scanArray(str) {
            //scans array & find position
            var tempArray = new Array() ;
            tempArray = str.split(',') ;
            //alert ("Temp Array Length "+tempArray.length);
            for(k=0;k<tempArray.length;k++) {
                  for(i=0;i<reqfields.length;i++) {
                        //alert ("looking for "+tempArray[k]+" in ReqFields ["+i+"]: "+ reqfields[i]);
                        if( reqfields[i] == tempArray[k] ) {
                              //alert("Found "+tempArray[k]);
                              document.form[tempArray[k]].value = "";
                              removeRequired (i,tempArray[k]) ;
      function displayArray(){
            document.form.outputbox.value = reqfields ;

      function removeRequired (pos,str)
            //alert ("Removed "+str+" from "+pos);

            function checkform(of)
                  var em,i,f,ty;
                  var labels,fieldnames;
                  fieldnames=new Array();
                        // reqfields=document.getElementById('required').value.split(',');
                              if(f.previousSibling && /img/i.test(f.previousSibling.nodeName)){
                                          case 'text':
                                          case 'textarea':
                                          case 'checkbox':
                                          case 'radio':
                                          /* extend as needed */
                        return false;
            function adderr(id,name,of)
                   var se,i,nli,na,newli,newa;
                  //i.title='This field has an error!';
                        var em=document.createElement('p');
                        em.appendChild(document.createTextNode('Please enter the following fields: '))
                        for(var i=0;i<of.getElementsByTagName('input').length;i++)
                                    var sb=of.getElementsByTagName('input')[i];
              '2px solid #c00';
                  if(id=='email' && !isEmailAddr(document.getElementById(id).value)){
                        pn.appendChild(document.createTextNode('Your email seems to be invalid'))      
/* Changes from errorlist example */
/* Changes end */

            function isEmailAddr(str)
                return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.