Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    ew1
    ew1 is offline
    New Coder
    Join Date
    Mar 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question checkCheckboxGroup broken after form consolidation

    Hi,

    Location: the web page in question (http://www.hr.arizona.edu/04_cb/finEd/allReg1.php)

    History: I had two different forms on two different pages. I was told to put them onto one web page, so that one form up is high on the page and the other form is near the bottom. Both forms just have checkboxes for registering for classes. Previously on each page, there was javascript that made sure that at least one class was chosen.

    Now: I put both forms on one web page and, as requested, are separated vertically by much space. Programmatically, I decided to do away with the two forms and consolidate them. I did this by deleting the ending form tag (</form>) for the first form and the beginning form tag (<form action=…>) for the second form. Programmatically, there is now only 1 form on the web page although physically it still looks like 2 separate forms.

    Each section of the form has it’s own ‘Next’ button (a submit tag). Why? Because if the user is looking at the upper form, they only see that section of the form and they may want to go ahead and sign up for the class. Likewise, if they only see the lower form, they will need a submit button there as well. That doesn’t seem to be the problem. I can hit either submit button and get to the next page fine.

    Problem: My problem is that now, in Netscape Navigator, after programmatic form consolidation, the javascript that verifies that at least one class has been chosen has suffered trauma.

    Specifically, the top “form” and it’s ‘Next’ button work in that it flags an error if no classes are chosen but submits fine when at least one class is chosen.

    This is not true of the bottom “form”. It always flags an error even if one class is chosen from it.

    You might want to tell me to keep the forms separate but here is why I did not: I want the user to be able to choose classes in both forms if they realize that there are 2 forms to choose from on this page without having to fill out their names and info 2 separate times. That way, they can be linked to either the top or bottom form from some other web page, pick a class, see the link that states that there are even more classes, choose one of those additional classes, press the ‘Next’ button, and see all their classes on the next screen.

    Code:
    Code:
    function checkForm(theForm) 
    {
    	if (! checkCheckboxGroup(theForm,'chosenClass[]')) return false
    }
    
    
    function checkCheckboxGroup(theForm,theGroupname) {
    	var theElements = theForm.getElementsByTagName("input");
    	for (var i = 0; i < theElements.length; i++) 
    	{
    		if (theElements[i].type == 'checkbox' && theElements[i].name == theGroupname && theElements[i].checked)
    			return true
    	}
    	//alert ('No checkboxes with name "' + theGroupname + '" are checked.');
    	return false
    }
    
    function submitIt(someForm)
    {
     //make sure they enter a class
     if (checkCheckboxGroup(document.forms.theForm,'chosenClass[]') == false)
     {
    	alert("You must select at least one class.");
      return false
     }
     return true
    }
    Any ideas?

    Thank you very much for reading all of this!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    A little bit intricate your presentation but... let's see

    At a first glance

    1. try get rid of the form object as parameter (as you said you have decided to have a single form on page).


    2. I don't sense the reason for you have a verifying function checkForm() which does nothing but call another function checkCheckboxGroup(). Why not directly the checkCheckboxGroup() from the submit event handler?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    ew1
    ew1 is offline
    New Coder
    Join Date
    Mar 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It turned out to be an html error. If you don't nest tables and td's and tr's exactly right, Netscape can't compute the javascript. IE lets all sorts of stuff pass and just keeps going.

    Thanks for your help!
    'Do or do not. There is no try.' --Yoda


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •