views:

43

answers:

1

Hello!

I have a form with a set of links and hidden inputs like this:

<div><%=link_to '&darr;', {}, {:href =>'#',
     :onclick => "return moveDown(#{photo.id});"}%></div>
<%= photo_form.hidden_field :position %>

How do I change input value when link is clicked without hard-coding input ids on client side? i dont want to use selectors also. is there any KISS solution?

thanks in advance!

A: 

First off I'd suggest using non-obtrusive Javascript. I presume you're trying to sort the list of links and keep track of their position. jQuery has built-in support for sortable/draggable functionality like this.

Also, this rails cast shows how to create such sortable lists (although it uses Prototype JS framework).

Eimantas