Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem executing 3 variables at once

Status
Not open for further replies.

stinkysGTI

Programmer
May 10, 2007
3
US
ok, I have a decent sized mail form. It's in 4 sections.

There's 3 variables I need to complete on each section:
1. check that all fields are completed
2. if all fields are completed, change graphic in section header from 'not completed' to 'completed'
3. hide current section and show next section

I can get it to validate the required fields and change the graphic, but can't get it to also hide and show proper sections.

I can when that is all I do, I just can't get all 3 at the same time. I'm not a javascript pro by any means, so my current code is needlessly extensive.

I don't know enough to consolidate and make a general function to use for all. I tried nesting other functions at the end of my validation, but I guess I'm not doing it right. I keep getting errors. So I instead dropped a section-specific function at the end [not efficient at all].

Like I said, the code is rather extensive, so I don't want to drop it in this post. Hopefully someone will get the idea. I can post the files on my site, if that'll help.
 
Like I said, the code is rather extensive, so I don't want to drop it in this post. Hopefully someone will get the idea.

We get the idea, the problem is we don't know if you would get the idea based on our answers w/o example code. I'll try to explain:


1. check that all fields are completed
2. if all fields are completed, change graphic in section header from 'not completed' to 'completed'
3. hide current section and show next section

1. Make a validation function that will return true if all fields are completed, else false.

2. In a function, change the graphics based on the return value of the validation function. It will look like this.

3. Assuming a "section" is a div, give it display:none and the next section a display:block.

Code:
if (validateAllFields()) {
   changeGraphic 
   document.getElementById("currentSectionDivID").style.display = "none";
   document.getElementById("nextSectionDivID").style.display = "block";
}
else {
   return false;
}

That's as descriptive as I can get with the code you posted.


[monkey][snake] <.
 
Yes, the sections are divs and I am using a none/block style changer. Then, I also use a style changer to switch the bg's of 'completed' and 'not completed'. The validation is where the problem is I guess. I was trying to use one big validation script for the entire form and all but the first continue buttons were getting confused.

I think I was just too focused on the way I was trying to do it and overcomplicated it.

Here's the page:

Thank you for your response monksnake
 
I'm actually working on it right now, and making it work. I think I just needed to reset my brain.

I was making it too complicated and after a few hours, it just built up the congestion in my brain :). Now, this is all I'm doing:

function validate_section1 ( ){
if ( document.FrontPage_Form1.series.selectedIndex == 0 )
{
alert ( "choose a time and day" );
valid = false;
return;
}
if ( document.FrontPage_Form1.number.selectedIndex == 0 )
{
alert ( "choose a number" );
valid = false;
}else{
changeObjectVisibility('section-02', 'block');
changeObjectVisibility('section-01', 'none');
changeObjectVisibility('section-03', 'none');
changeObjectVisibility('section-04', 'none');
sectionOneComplete();
}
}


By the way, I did NOT use frontpage :). I'm reworking someone's old form and trying to keep as much of it the same as possible because the form's action goes to a third-party.

Thanks for lookin at it cLFlaVA. I always code for FF first ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top