How do I add a third variable to a jQuery "each" function? -
i've got bit of tricky issue. i'm trying add third parameter following function/loop , have hit wall. help?
$.each(studentselectvalues, function(key, value) { $('select[name="cf_student"]') .append($("<option></option>") .attr("value",key) .text(value)); });
here's code looks studentselectvalues
variable:
studentselectvalues = { '1': 'my 1st option', '2': 'my 2nd option', '3': 'my 3rd option' }
what i'm doing populating select options shown above. goal add third attribute each select. have clue how accomplish this?
thanks in advance.
i'd make studentselectvalues
hash array of hashes ... way can use many attributes need:
studentselectvalues = [ { id: '1', key: 'my 1st option', text: 'first' }, { id: '2', key: 'my 2nd option', text: 'second' }, ]; $.each(studentselectvalues, function(index, item) { $('select[name="cf_student"]') .append($("<option></option>") .attr("value",item.key) .text(item.text)); });
Comments
Post a Comment