Reputation: 5370
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.
Upvotes: 1
Views: 2145
Reputation: 2881
$("h img").click(function() {
var imageId = $(this).attr("src"); // or can use this.src instead
$("#frame:hidden").val(imageId);
});
Upvotes: 1