Topic: how to dinamically assign id to checkbox as i loop through

iam using
<%= check_box_tag ( "id","word",false, :onclick => remote_function( ))%>
for sending remotecall but i want  "id" and value ie "word" to be diff as i load

like iam looping through records as shown below

<%for x in @xrecords%>
<%= check_box_tag ( "<%x.id%>","<%x.value%>,false, :onclick => remote_function( ))%>
<%end%>
but this is not taking  <%x.id%> but throwing error at that line,please let me know if there is a way to do this ie assigning the id dinamically as i loop


*i was using check_box_tag as i need to do remote call if there is a way to do that remote call using <input type='checkbox' value='Toggle Selected' id='chk1' /> please let me know as it allows me to assign ids dynamically

please help me on this

Re: how to dinamically assign id to checkbox as i loop through

<%for x in @xrecords%>
<%= check_box_tag ( "<%x.id%>","<%x.value%>,false, :onclick => remote_function( ))%>
<%end%>

you are trying to use rails tags inside a rails tag... try

<%= check_box_tag ( x.id, x.value ,false, :onclick => remote_function( ))%>

if you want to use a variable and a string..

<%= check_box_tag ( "#{x.id}","#{x.value}",false, :onclick => remote_function( ))%>

Re: how to dinamically assign id to checkbox as i loop through

cool,thanks man..ur gr8 smile

Last edited by kiran2215 (2007-10-18 15:00:48)

Re: how to dinamically assign id to checkbox as i loop through

hi i have one more Q its abt
<%= observe_field

it is doing ajax post back when i check and uncheck the check box but its passing the value when i check the check box but not when i uncheck it,is there any way we could make it work so that it always sends value,i need this as i cant use 'check_box_tag ' as i need to call a javascript code too as far as i know with 'check_box_tag' we cant call javascript and the remote function with it if we can please let me know...or please let me know how we can make observe field to return the value when the checkbox is unchecked too

Thanks