Note that there are some explanatory texts on larger screens.

plurals
  1. POStyle knockout.js radio buttons with image
    primarykey
    data
    text
    <p>I'm using knockout.js to display the price and id when a user select a radio button here is the script:</p> <pre><code>&lt;div data-bind="with: bin2ViewModel"&gt; &lt;div class="divRadiobtns" data-bind="foreach: availableGroups"&gt; &lt;input type="radio" class="radioOptions" name="retailerGroup" data-bind="checked: $parent.selectedGroupOption, value: price" /&gt; &lt;/div&gt; &lt;div data-bind="with: selectedRetailerGroup"&gt; &lt;span class="actualPrice" data-bind="text: price" /&gt; &lt;/div&gt; &lt;div data-bind="with: selectedRetailerGroup"&gt; &lt;input type="hidden" class="hiddenValue" data-bind="value: retailerproductId" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>knockout.js:</p> <pre><code>&lt;script type="text/javascript"&gt; //&lt;![CDATA[ var Bin2ViewModel = function () { var self = this; this.selectedRetailerGroup = ko.observable(); this.selectedGroupOption = ko.observable(); this.selectedGroupOption.subscribe(function (newVal) { var items = $.grep(self.availableGroups(), function (item) { return item.price() == newVal; }); self.selectedRetailerGroup(items[0]); }); this.selectedGroup = ko.observable(); this.availableGroups = ko.observableArray( [ new RetailerViewModel("302852", "£2.55"), new RetailerViewModel("21290", "£1.80") ]); } var RetailerViewModel = function (retailerproductId, price) { this.retailerproductId = ko.observable(retailerproductId); this.price = ko.observable(price); } ko.applyBindings({ bin2ViewModel: ko.observable(new Bin2ViewModel()) }); //]]&gt; &lt;/script&gt; </code></pre> <p>I want to style the radio button with images so i have tried:</p> <p>css:</p> <pre><code> .radioOptions { background: url("http://static.e-talemedia.net/content/images/odditiesyellowselector.png") no-repeat scroll 0 0 transparent; margin-bottom: 25px; margin-top: 17px; } .radioOptions-checked { background: url("http://static.e-talemedia.net/content/images/odditiesyellowblackselector.png") no-repeat scroll 0 0 transparent; } </code></pre> <p>But i can t get it wokring - has anyone got any idea how i can style in knockout.js? </p> <p>I was previouisly using jquery as follows:</p> <pre><code>&lt;%--&lt;script type="text/javascript"&gt; //&lt;![CDATA[ $(function () { $('input:radio').hide().each(function () { var label = $("label[for=" + '"' + this.id + '"' + "]").text(); $('&lt;a title=" ' + label + ' " class="radio-fx ' + this.name + '" href="#"&gt;&lt;span class="radio"&gt;&lt;/span&gt;&lt;/a&gt;').insertAfter(this); }); $('.radio-fx').click(function () { $check = $(this).prev('input:radio'); var unique = '.' + this.className.split(' ')[1] + ' span'; $(unique).attr('class', 'radio'); $(this).find('span').attr('class', 'radio-checked'); $check.attr('checked', true); var rpPrice = $('input[name=selectRetailer]:radio:checked'); // Here I have an ID $(".actualPrice").html(rpPrice.val()); // var rpId = $('input[name=selectRetailer]:radio:checked'); // $(".actualPrice").html(rpId.val()); }).on('keydown', function (e) { if (e.which == 32) { $(this).trigger('click'); } }); }); //]]&gt; &lt;/script&gt;--%&gt; </code></pre> <p>But this threw out the knockout.js</p> <p>any tips appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload