3

How to set option selected when using jqtransform on select element.

I'm using jqtransform for my form , and I want to set appropriate option value to be selected when I'm retrieving saved data from database.

Anushka
  • 2,434
  • 1
  • 17
  • 14

2 Answers2

5

I believe you would set the value of select the same way as without using the jqTransform.

E.g.

$('#mySelect').val('myVal');

Edit:

Well, this is really ugly but should work:

var mySelect = $('#mySelect');

//find the current selected option
var myOption = mySelect.find('option[value='+mySelect.val()+']');

//find the index of that option
var index = $('#mySelect option').index(myOption);

//trigger the click on the corresponding jqTranfsform element
mySelect.prev('ul').find('li').eq(index).find('a').click();
algiecas
  • 2,108
  • 14
  • 13
3

You can call onchange event. jqtransform has change() method.

$('#mySelect').val('myVal').trigger('change');

It work's :)