Looping throught current select
- $("select[id^='ticket_types_']").each(function () {
- var selectName = this.name;
- var selectId = this.id;
- var buttons;
-
- $("select[id=selectId] option").each(function () {
- alert("aa");
- buttons += "<input type='button' value='" + this.value + "'/>";
- });
- alert(buttons);
- $("select[id=selectId]").replaceWith(buttons);
- // add a hidden element with the same name as the select
- var hidden = $('<input type="hidden" name="'+selectName+'">');
- hidden.val($("select[id=this.id]").val());
- hidden.insertAfter($("select[id^='ticket_types_']"));
- $("select[id=this.id] option").unwrap().each(function() {
- var btn = $('<div class="btn">'+$(this).text()+'</div>');
- if($(this).is(':checked')) btn.addClass('on');
- $(this).replaceWith(btn);
- });
- });
I am trying to change the option in a select to buttons. There is more than one select on the page but tehy all have an id starting with ticket_types_
My problem is that it isn't going into
- $("select[id=selectId] option").each(function () {
- alert("aa");
- buttons += "<input type='button' value='" + this.value + "'/>";
- });
How do I get it to pick up the options for the current Select Id. selectId has the correct Id value
Thanks