# How to add a dynamic value for a tag's id attribute

**URL:** <https://www.ruby-forum.com/t/how-to-add-a-dynamic-value-for-a-tags-id-attribute/134686>\
**Category:** Rails\
**Created:** [April 14, 2008, 3:26am UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-value-for-a-tags-id-attribute/134686 "2008-04-14T03:26:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 14, 2008, 3:26am UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-value-for-a-tags-id-attribute/134686/1 "2008-04-14T03:26:31Z")

</div>

how to add a dynamic value for a tag’s id attribute in the ajax  
call.For example:several “

” and  
“\<%=link\_to\_remote(“MoreInfo”,:update=\>”#{product.id}",:url=\>{:action=\>“more\_info”,:id=\>product},:method=\>:get)-%\>"in  
a page,i want every ajax result to replace its own “”,instead of the same  
one.  
so how to add a dynamic value for a tag’s id attribute

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 14, 2008, 6:57am UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-value-for-a-tags-id-attribute/134686/2 "2008-04-14T06:57:49Z")

</div>

Guo Y. wrote:

> how to add a dynamic value for a tag’s id attribute in the ajax  
> call.For example:several “\<td id=”#{product.id}" colspan=“4”

Just a note that’s an illegal ID. In summary, an HTML ID attribute must  
be  
unique to its page, and must satisfy naming conventions commonly  
ascribed to  
language variables, such as JavaScript variables. An ID may not contain  
punctuation or start with a number.

Always go id=“product\_\<%= product.id %\>”, and also think about making  
the  
product\_ prefix more context-specific.

> align=“center”\>" and  
> “
> 
> \<%=link\_to\_remote(“MoreInfo”,:update=\>”#{product.id}",  
> :url=\>{:action=\>“more\_info”,:id=\>product},:method=\>:get)-%\>"in

:id =\> product.id

You might be passing the whole product by copy there. I’m not sure what  
it will  
turn into!

> a page,i want every ajax result to replace its own “”,instead of the same  
> one.

Put the useful prefix on the id.

Next, think about handling the Ajax call with render :update do … and  
put  
inside that an update\_html directed at that id.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![daociyiyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/0ea827/32.png) [@daociyiyou](https://www.ruby-forum.com/u/daociyiyou)\
**Post date:** [April 14, 2008, 12:01pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-value-for-a-tags-id-attribute/134686/3 "2008-04-14T12:01:08Z")

</div>

Thank you Phlip.But i also want to ask you how to make an ajax call to  
bring out an some size window when click a link.Just tell me the outline  
instead of detail about how to.Thank you!
