I’m trying to change the value of a hidden input field to the source of a clicked image. For some reason, the field isn’t getting the value. What am I doing wrong?
Images…
<li><h><img src="/images/frame1.png"></h></li>
<li><h><img src="/images/frame2.png"></h></li>
<li><h><img src="/images/frame3.png"></h></li>
Hidden field:
<%= f.hidden_field :frame, :id => "frame", :name => "frame" %>
Jquery code:
<script type="text/javascript" language="javascript">
$(function() {
$("h img").click(function() {
var imageId = $("img").attr("src");
$("#frame").val(imageId);
});
});
</script>
Thank you.
1 Answer