0

This is more of a coding practice question, I want to set variables within a javascript object / array from a html form.

I am currently doing this using the onkeyup and passing the value to a set function. e.g: (along the lines of )

 onclick="item.setVar('retouch', this.value); return false;"

 setVar: function(variable, value){
    this[variable] = parseInt(value);
 }

is there a better way of doing this or is it down to personal preference.

Thanks all for your help :)

1
  • 1
    "is there a better way of doing this": please define better. Better how? Commented Aug 21, 2013 at 15:31

1 Answer 1

0

Personal preference if using vanilla Javascript, but why the function even?

onclick="item['retouch'] = parseInt(this.value); return false;"

Maybe you should look into a JS model binding library, like Knockout, Backbone or Angular?

Sign up to request clarification or add additional context in comments.

Comments