Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7577 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi, I'm building a page with conditional value lists loaded into Javascript arrays and I'm stuck!!

on the page below I've loaded some of the arrays and this was going OK until I've reached the second level.

In my example, if you choose "The Grocer" and then choose " the grocer display" it works OK, but not if you choose "the grocer recruitment". If I comment out the "If" statement for "the grocer display", the "recruitment" choice starts working.

Apologies for getting rather OT here, but can someone point me to the errors in my JavaScript please??

http://www.william-reed.net/adsizes8.htm

thanks, jeff

Posted

Hi, It's not my strong side either, which is why it doesn't work ???-(

........ but I figured there are guys around here who are good at this stuff!

thanks for the tip, I'll have a look, jeff

Posted

Hi Jeff, I've made a few adjustments your script so that it works. You can view the updated code at http://mariano.petersonpages.com/demo/javascript/dynamicLists.htm

The original problem was caused by a dangling if statement somewhere in your code. I tried to format the code (indent if and for blocks, etc) in my code editor (Homesite), and had trouble matching open/close brackets. Anyway, I'm fairly sure that is where the problem was.

I've also written another version of the code which is easier to read and maintain, and also more extensible: http://mariano.petersonpages.com/demo/javascript/dynamicLists_improved.htm

This version assigns values attributes to each select option, which makes the code more manageable. Option values are useful because they allow you to easily change the visible text for an option without having to rewrite code in other places -- just be sure that your surrounding code works with the value attributes of the select list and not the text.

I also reduced the function calls in the HTML body to just one parameter, "this.form". This is easier to read and provides a relative path to the form which will work even if the form name changes at a future date. I moved the functionality of obtaining a reference to the select list inside the function, instead of the inside the function call. This helps encapsulate the code more, which helps reduce bugs. Also, if the function ever needs to change the select lists it acts upon, you only have to change code in one place, instead of through out your HTML code smile.gif

Since there were multiple places where select lists were being re-populated, I created a new function which encapsulates this functionality. This removed a lot of tedious code from the main logic functions, which made them easier to read. Also, if you ever need to re-populate a select list anywhere else you have a handy function ready to go.

Hope this helps!

Posted

Hi Mariano!

No problem it was one of those 'favorites' that never got read or used....I also struggeled with the IF and ELSE IF attempt and had no luck... frown.gif

Mariano & Jeff

Note:

>if user decides to go for "the Grocer" --> "The Grocer Display" the user will get LOCKED into this selection and can not change his mind eg. going for "The Groceer Recruit"......and ever a page refresh will not fix it- only full URL relaod will....

My stupid suggestion to quick & dirty fix [reset] button smile.gif or for more "sophisticated" approach an option in "child menu" to re-set pert to 1 step back.....but I don't know the whole picture so maybe there is more to this.

Take care!

oops just saw it, Mariano already wrote a reset function grin.gif it jsut didn't fire.....

Posted

Awesome!

Thanks guys, I was getting really lost here because the original brief called for just TWO levels (publication > size) and then at the last minute someone remembered that sizes varied according to section.

I guess it was my own fault for trying to add a bit instead of starting again and I got really lost.

Thanks again for your expert help

regards, jeff

PS - I'm definitely going to use the "improved" version. "Case" is just a much more elegant way of dealing with this and very easy to add to .

This topic is 7577 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.