Kelvin: I should have known that syntax was available. I use it all the time in ColdFusion, but didn't realize I could use it in JavaScript too. I know to avoid eval, but thought I had no choice in this case. You can be sure I'll use this method! :o)

Klaus: Thanks so much for your comments on this subject too.

You guys are so awesome! I learn something new *every* day! :o)

Cheers,
Chris

Kelvin Luck wrote:
                var obj = new Object;
                // all inputs of type text, hidden, select and textarea
$("input:text,input:hidden,select,textarea").each(function(){
                    eval("obj." + this.name + " = '" + this.value + "';");
                });

Or even:

var obj = {};
$("input:text,input:hidden,select,textarea").each(function(){
        obj[this.name] = this.value;
});

This solution avoids using eval because:

* It will still work if one of your values has a single quote (') in.
* It is faster (I think?) and cleaner.


Hope that helps,

Kelvin :)

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/


--
http://cjordan.info

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to