How Can I Set The Value Of A Hidden Input Field Using Jquery?
I am attempting to set the value of a hidden input field to the same as the value of a clicked link. This is what I have attempted which doesnt work: $(document).ready(function(){
Solution 1:
use the val method
$("#delete_value").val(deleteID);
also for data attributes you might want to use the data method
$(this).data('value');
links:
Solution 2:
For all form elements you need to use .val()
:
$("#delete_value").val(deleteID);
Solution 3:
A complete example you (http://jsfiddle.net/79HEY/):
HTML
<form id="deleteform" action="delete_post.php" method="POST">
<p>Please confirm you want to delete this post.</p>
<input type="submit" data-id="100" id="delete_submit" name="delete_submit" value="confirm" />
<input type="hidden" id="delete_value" value="" />
</form>
JavaScript
$(document).ready(function(){
$("#deleteform").submit(function(){
var deleteID = $("#delete_submit").data("id");
$("#delete_value").val(deleteID);
return true;
});
});
Post a Comment for "How Can I Set The Value Of A Hidden Input Field Using Jquery?"