0

I have following generated code and tried to retrive the radio button value or checked from below html generated code

HTML code generated :::

    <input type="radio"      name="mergedServiceSets[0].cdaQuestionnaireresponses[0].questionnaire.value" id="SetUpTest_mergedServiceSets_0__cdaQuestionnaireresponses_0__questionnaire_valueY" value="Y" class="mergedServiceSets[0].cdaQuestionnaireresponses[0].questionInputRadio" onchange="javascript:dataModified();"/>&nbsp;Yes<br />

    <input type="radio" name="mergedServiceSets[0].cdaQuestionnaireresponses[0].questionnaire.value" id="SetUpTest_mergedServiceSets_0__cdaQuestionnaireresponses_0__questionnaire_valueN" value="N" class="mergedServiceSets[0].cdaQuestionnaireresponses[0].questionInputRadio" onchange="javascript:dataModified();"/>&nbsp;No<br />

Jquery1.6.1 used :

var questionInputRadio = $(".mergedServiceSets[" + i + "].cdaQuestionnaireresponses[" + j + "].questionInputRadio");

where i and j are passed dynamically . or

alert("questionInputRadio===" + $(".mergedServiceSets[0].cdaQuestionnaireresponses[0].questionInputRadio").val());

Actual results ::: undefined is displaying when i see in alert box .

It never works for index based classes or ids in jquery . please help

James Montagne
  • 77,516
  • 14
  • 110
  • 130

1 Answers1

1

You need to escape [, ] and . in your selector. Something like:

$(".mergedServiceSets\\[" + i + "\\]\\.cdaQuestionnaireresponses\\[" + j + "\\]\\.questionInputRadio");

Edit: I'm actually not sure if those characters are even technically valid.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
  • Hi Kingjiv, It worked. Some times i must need to have the above format for name attribute as ( name value is going to server side with that structure) and i can change the format for css class . Do you have any alternative mechanism if the above syntax is incorrect and why the above format is not technically correct . please answer .. Appreciate for your time – Venkat Keesara Jun 22 '11 at 14:00
  • http://stackoverflow.com/questions/448981/what-characters-are-valid-in-css-class-names seems to say that those characters are invalid in a css class. I would probably use `-` and `_` as separators personally. – James Montagne Jun 22 '11 at 14:15