Upon clicking a button with dynamic id, I want to put dst.district into a textbox with id district.
I have written following code, but it’s currently not working.
<input name="" type="text" class="dist1" id="district">
<% @districts.each do |dst|%>
<div id="dist_<%= dst.id%>" class="districtname"><%= dst.district %></div>
<input id="select_<%= dst.id%>" type="button" value="Select" class="gbutton" />
<script type="text/javascript">
$("#select_<%= dst.id %>").click({
$("#district").val("<%= dst.district %>");
});
</script>
<%end%>
Thank you in advance.
Just follow this code:
and