hello i want to make a script that is user configurable. so the user can define his own variables. how can i find what are the variables he defined? something like this: script1.js // zone for defining the vars var user_var1=1; var user_var2=2; // my function function show_vars() { foreach ( defined variables by user ) alert( variable name ); } i hope i'm clear enough thanks
What's your purpose for doing this? If you don't know what variables the user is going to define, how are you going to know what to do with them?
i want to make a tool for validating forms so the user can set their "type" of input with his own properties to validate like this <input type="text" rel="name" /> so he set var min_name=5 and the js makes the validation for minimum 5 chars in that input i know it might seem stupid but i want to make this script unobtrusive and EASY configurable for any form. all you have to add is a rel for manatory fields and in rel the kind of validation defined or customized by you. what do you think?
Make an object. I think you can iterate those like var obj = new Object(); obj["asdf2"] = "WTF"; obj["asdfef4"] = "WTF"; obj["asdf34333"] = "WTF"; for(var i in obj) { alert(obj[i]); } Code (markup):
The HTML quickform package at http://pear.php.net writes server side and client side validation for you. It sounds like what you are trying to do. You can look at their code I guess.