Required fields

Posted on 2005-03-23
Medium Priority
Last Modified: 2010-04-01

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];
                        em.style.border='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}$/);
Question by:pikapi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

vijaydogra earned 200 total points
ID: 13667862

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
The Summer 2017 Scholarship Winners have been announced!
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question