views:

577

answers:

5
<script type = "text/javascript">
        var First_Array = new Array();
        function reset_Form2() {document.extraInfo.reset();}
        function showList1() {document.getElementById("favSports").style.visibility="visible";}
        function showList2() {document.getElementById("favSubjects").style.visibility="visible";}
        function hideProceed() {document.getElementById('proceed').style.visibility='hidden';}

    function proceedToSecond ()
 {
        document.getElementById("div1").style.visibility="hidden";
        document.getElementById("div2").style.visibility="visible";
        document.getElementById("favSports").style.visibility="hidden";
        document.getElementById("favSubjects").style.visibility="hidden";
 }

 function backToFirst () {
  document.getElementById("div1").style.visibility="visible";
  document.getElementById("div2").style.visibility="hidden";
  document.getElementById("favSports").style.visibility="visible";
  document.getElementById("favSubjects").style.visibility="visible";
 }

 function reset_Form(){
  document.personalInfo.reset();
  document.getElementById("favSports").style.visibility="hidden";
  document.getElementById("favSubjects").style.visibility="hidden";
 }

 function isValidName(firstStr) {
  var firstPat = /^([a-zA-Z]+)$/;

  var matchArray = firstStr.match(firstPat);
  if (matchArray == null) {
   alert("That's a weird name, try again");
   return false;
  }

  return true;
 }

 function isValidZip(zipStr) {
  var zipPat =/[0-9]{5}/;
  var matchArray = zipStr.match(zipPat);
  if(matchArray == null) {
   alert("Zip is not in valid format");
   return false;
  }
     return true;
 }

 function isValidApt(aptStr) {
  var aptPat = /[\d]/;
  var matchArray = aptStr.match(aptPat);
  if(matchArray == null) {
   if (aptStr=="") {
    return true;
   }
   alert("Apt is not proper format");
   return false;
  }

        return true;
 }

 function isValidDate(dateStr) {
  //requires 4 digit year:

  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

        var matchArray = dateStr.match(datePat);
  if (matchArray == null) {
   alert("Date is not in a valid format.");
   return false;
  }
  return true;
 }

 function checkRadioFirst() {
  var rb = document.personalInfo.salutation;

  for(var i=0;i<rb.length;i++) {
   if(rb[i].checked) {
    return true;
   }
  }
        alert("Please specify a salutation");
  return false;
 }

 function checkCheckFirst() {
  var rb = document.personalInfo.operatingSystems;

  for(var i=0;i<rb.length;i++) {
   if(rb[i].checked) {
    return true;
   }
  }
        alert("Please specify an operating system") ;
  return false;
 }

 function checkSelectFirst() {
  if ( document.personalInfo.sports.selectedIndex == -1)
  {
   alert ( "Please select a sport" );
   return false;
  }
  return true;
 }

 function checkRadioSecond() {
  var rb = document.extraInfo.referral;

  for(var i=0;i<rb.length;i++) {
   if(rb[i].checked) {
    return true;
   }
  }

        alert("Please select form of referral");
  return false;
 }

 function checkCheckSecond() {
  var rb = document.extraInfo.officeSupplies;

  for(var i=0;i<rb.length;i++) {
   if(rb[i].checked) {
    return true;
   }
  }
        alert("Please select an office supply option");
  return false;
 }

 function checkSelectSecond() {
  if ( document.extraInfo.colorPick.selectedIndex == 0 ) {
   alert ( "Please select a favorite color" );
   return false;
  }
        return true;
 }

    function check_Form(){
        var retvalue = isValidDate(document.personalInfo.date.value);
  if(retvalue) {

            retvalue = isValidZip(document.personalInfo.zipCode.value);
            if(retvalue) {

                retvalue = isValidName(document.personalInfo.nameFirst.value);
                if(retvalue) {

                    retvalue = checkRadioFirst();
                    if(retvalue) {

                        retvalue = checkCheckFirst();
                        if(retvalue) {

                            retvalue = checkSelectFirst();
                            if(retvalue) {

                                retvalue = isValidApt(document.personalInfo.aptNum.value);
                                if(retvalue){
                                    document.getElementById('proceed').style.visibility='visible';

                                    var rb = document.personalInfo.salutation;

                              for(var i=0;i<rb.length;i++) {
                                        if(rb[i].checked) {
                                            var salForm = rb[i].value;
                                        }
                              }

                                    var SportsOptions = "";
                                    for(var j=0;j<document.personalInfo.sports.length;j++){
                                        if ( document.personalInfo.sports.options[j].selected){
                                            SportsOptions += document.personalInfo.sports.options[j].value + " ";
                                        }
                                    }

                                    var SubjectsOptions= "";
                                    for(var k=0;k<document.personalInfo.subjects.length;k++){
                                        if ( document.personalInfo.subjects.options[k].selected){
                                            SubjectsOptions += document.personalInfo.subjects.options[k].value + " ";
                                        }

                                    }

                                    var osBox = document.personalInfo.operatingSystems;
                                    var OSOptions = "";
                                    for(var y=0;y<osBox.length;y++) {
                                        if(osBox[y].checked) {
                                            OSOptions += osBox[y].value + " ";
                                        }
                                    }


                                    First_Array[0] = salForm;
                                    First_Array[1] = document.personalInfo.nameFirst.value;
                                    First_Array[2] = document.personalInfo.nameMiddle.value;
                                    First_Array[3] = document.personalInfo.nameLast.value;
                                    First_Array[4] = document.personalInfo.address.value;
                                    First_Array[5] = document.personalInfo.aptNum.value;
                                    First_Array[6] = document.personalInfo.city.value;
                                    for(var l=0; l<document.personalInfo.state.length; l++) {
                                        if (document.personalInfo.state.options[l].selected) {
                                            First_Array[7] = document.personalInfo.state[l].value;
                                        }
                                    }
                                    First_Array[8] = document.personalInfo.zipCode.value;
                                    First_Array[9] = document.personalInfo.date.value;
                                    First_Array[10] = document.personalInfo.phone.value;
                                    First_Array[11] = SportsOptions;
                                    First_Array[12] = SubjectsOptions;
                                    First_Array[13] = OSOptions;

                                    alert("Everything looks good.");
                                    document.getElementById('validityButton').style.visibility='hidden';
                                }
                            }
                        }
                    }
                }
            }
        }
    }

 /*function formAction2() {
  var retvalue;
  retvalue = checkRadioSecond();
  if(!retvalue) {
   return retvalue;
  }

  retvalue = checkCheckSecond();
  if(!retvalue) {
   return retvalue;
  }

  return checkSelectSecond() ;
 }   */
</script>

This is just a sample of the code, there are alot more functions, but I thought the error might be related to surrounding code. I have absolutely no idea why, as I know all the surrounding functions execute, and First_Array is populated.

However when I click the Proceed to Second button, the onclick attribute does not execute because Firebug says proceedToSecond is not a function

button code:

<input type="button" id="proceed" name="proceedToSecond" onclick="proceedToSecond();" value="Proceed to second form">
A: 

Maybe there is an error in your Javascript before that snippet given by you. If so, the rest will not be parsed by Firefox and then your function will not be defined.

Martin
I've just shown all the code.. although its a bit messed up on here. there is a <script blah blah> at top.. thats the only thing missing
If your JS code is faulty, there must be some output in Firefox' error console. What does it say?
Martin
A: 

The problem was resolved by changing proceedToSecond() to doIt() in both the call and the function name. I have no idea why

This indicates a conflict of some kind, could you possibly paste the entire source code somewhere, preferably on http://pastebin.com/ ?
Sune Rievers
A: 

Hmm... I always used javascript:function_name() instead of function_name() because a few times the javascript didn't run. The name tag for the html snippet might have to be changed to a slightly different name because javascript might be getting it mixed up. Can you show us the entire javascript file because there may be a mistake/syntax error somewhere at the bottom/top.

alexy13
A: 

It works on my computer, Firefox 3.5.5, Firebug 1.4.3, when inserting your code into an empty html document (<html><head/><body> code </body></html>)

Maybe there is another bug somewhere in your DOM, or in some of your other functions?

Could you possibly paste the entire source here, or maybe on a pastebin site?

Sune Rievers
+1  A: 

I had the same problem, and it's because you have a form with the same name as your function. JavaScript doesn't seem to be able to distinguish between the two, so you get the "not a function" error.

Wesley May
The same type of thing happens if you try to name a global variable "`status`", but it varies across browsers. It's really stupid, if you ask me.
Joey Adams