views:

46

answers:

7

How do i put the variables in this single quotes and double quotes iam confused

  var rdb ='<input type="radio"  id="rdb_"'+ i +' data-value1='+  labelvalue[1]  +'  data-value2='+ data[i].value +'>';
   t += '<tr><td>'+rdb+'</td><tr>';

Here variable "i" is dynamic , "labelvalue[1] " is dynamic and "data[i].value " is dynamic Due to this iam not able to produce the Dynamic Radio buttons . So the View source looks in this way

How do i correctly produce this using single quotes and double quotes input type="radio" id ="rdbacc_0" data-value1="testRYSTAYTYTAST" data-value="007"

+2  A: 
T.J. Crowder
A: 

you seem to be almost there, some of your quotes are in the wrong place

 var rdb ='<input type="radio"  id="rdb_'+ i +'" data-value1="'+  labelvalue[1]  +'"  data-value2="'+ data[i].value +'">';
   t += '<tr><td>'+rdb+'</td><tr>';
Pharabus
A: 

this should do it ..

var rdb ='<input type="radio"  id="rdb_'+ i +'" data-value1="'+  labelvalue[1]  +'" data-value2="'+ data[i].value +'">';
Gaby
A: 
var rdb ='<input type="radio"  id="rdb_'+ i +'" data-value1="' +  labelvalue[1]  +'"  data-value2="'+ data[i].value + '">';

t += '<tr><td>' + rdb + ' </td><tr>';

should do it

Ross
A: 

Hmm, here's some thinking outside the box. Don't put yourself in such a difficult to read situation. Use .attr().

Tudorizer
+1  A: 

You might want to replace such "constructs" with an Array. That has a better readability and in most cases is faster than string concat by +.

var rdb = [
    '<input type="radio"  id="rdb_"',
    i,
    '"data-value1="',
    labelvalue[1],
    '"data-value2="'
    data[i].value,
    '>'
];

rdb.join('');
jAndy
@Someone: this answer was just a suggestion for better readability. Please select T.J. Crowder's answer as correct, since he really answered your question.
jAndy
+1  A: 

If you are using jQuery this would probably function and read much better:

$('<input />', {
    'id':'rdb_'+i,
    'type':'radio',
    'data-value1':labelvalue[1],
    'data-value2':data[i].value
}).appendTo('<tr><td></td></td>');
path411