MyBB Community Forums

Full Version: Help with an array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on my board profiles using the excellent custom profilefields from RateU. One of the things I am trying to do is to make a list of options a user can choose from, and on one of the chosen options a second profile field input will open allowing the user to add more detail.

I have it all working, but the javascript is clunky. I made a jsFiddle for the code. The problem is that in order to REHIDE the field I am checking each element on change and I think that should be an array but I am not sure how....

http://jsfiddle.net/leefish/qSdUn/

I DON'T want to use jQuery for this, but I am open to Prototype code suggestions Big Grin Help appreciated.
not sure how an array would help here, why not build a new function that takes the field name as input and then just feed that to the function for each field?

That would be smaller and faster
Thanks Danny, so how would I do that then?
javascript is not my strong point.

but should be

function whatever($variable1, $variable2) {
form.$variable.value
}

now thats very very rough pseudo code. But basically if you are performing the exact same thing on every field you would just box that into a function and call the function with the form field as the $variable

Hope that makes sense. I have my head in something else at the moment so can't specifically alter what you have for you at the moment
Thank you Danny, I can also make pseudo code, it is the actual code that eludes me Big Grin

The current code works, it is old fashioned js and is not taking advantage of any library. It just seems that rather than iterating if id x then do y until all ids are exhausted then using get all element ids in array z would surely be more efficient.

Still looking for an answer.
efficiency would be a close thing, it's probably more about the cleanliness of code here. You'll probably get a better answer on stackoverflow or prototype forums.

Otherwise I will try and write something out for you later, I am writing a fairly large plugin at the moment so bear with me for a few days