Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:33:25+00:00 2026-06-12T03:33:25+00:00

Concider a jQuery Mobile list containing a radio button and a label for it.

  • 0

Concider a jQuery Mobile “list” containing a radio button and a label for it.

<!-- ko foreach: $data.answers -->
<input type="radio" name="radio-choice" data-bind="attr: { id: [...] }" />
<label data-bind="attr:{ for: [...] }">Label</label>
<!-- /ko -->

In order to work, the for attribute of the label needs to be the same as the id of the input.

REPLACEMENT FOR [...]            RESULTS IN
$index                           ok
'radio-nr-'+$index               fails
$root.testFunction(1)            ok
$root.testFunction($index)       fails
'radio-nr-'.concat(1)            ok
'radio-nr-'.concat($index)       fails

where

function testFunction(a) {  return "radio-nr-"+a; };

Why do all my attempts of concatenating the $index fail?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:33:26+00:00Added an answer on June 12, 2026 at 3:33 am

    From the $index documentation:

    Unlike the other binding context properties, $index is an observable

    So you need to write $index() (note the parenthesis) in your binding:

    <!-- ko foreach: $data.answers -->
    <input type="radio" name="radio-choice" 
                        data-bind="attr: { id: 'radio-nr-' + $index()  }" />
    <label data-bind="attr:{ for: 'radio-nr-' + $index() }">Label</label>
    <!-- /ko -->
    

    A working sample in JSFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider: <div id=message></div> The jquery says: var html_to_insert = '<div id=mynewdiv><input id=myfield name=myfield type=text
Consider the following JSF (& jQuery Mobile) markup: <h:form> <a href=#login data-rel=popup>Please login</a> <h:outputText
Consider the following html snippet <!DOCTYPE html> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.4.2.js ></script> <script
We've recently started a small-ish project for a mobile site demo w/.NET4; jquery-mobile has
I am using PhoneGap 1.5.0, jQuery 1.7.1 and jQuery mobile 1.0.1 and trying to
Consider the following function using jQuery: function getVal() { jQuery.get('/relative/url/', function (data) { return
Consider the code given at the end, which makes use of jQuery Mobile to
jQuery Mobile 1.0 final is out Important: Many of the tutorials are old and
In a jQuery Mobile application, I'm using Ajax to load a page with dynamic
I am working on a hybrid application using jQuery Mobile. The issue is I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.