Help with an array
#1
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.
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#2
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
Reply
#3
Thanks Danny, so how would I do that then?
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#4
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
Reply
#5
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.
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#6
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)