Current location: Hot Scripts Forums » General Web Coding » JavaScript » checkCheckboxGroup broken after form consolidation


checkCheckboxGroup broken after form consolidation

Reply
  #1 (permalink)  
Old 01-12-05, 12:00 PM
ski_woman's Avatar
ski_woman ski_woman is offline
Newbie Coder
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question checkCheckboxGroup broken after form consolidation

Hi,

Location: the page in question

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Limit the form submission according to time bionicsamir PHP 7 05-10-04 12:10 AM
make form box TEXT? lylesback2 JavaScript 2 04-05-04 07:58 PM
submit form? tcooper PHP 5 12-12-03 04:30 PM
SQL database registration form help vinhkhuong PHP 3 10-10-03 04:49 AM


All times are GMT -5. The time now is 10:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.