Reputation: 1181
I'm trying to set the value of the hidden field below using jQuery.
<input type="hidden" value="" name="testing" />
I'm using this code:
var test = $("input[name=testing]:hidden");
test.value = 'work!';
But its not working. What's wrong with my code?
Upvotes: 118
Views: 271096
Reputation: 1
you can set value to input hidden filed in this way also
<input type="hidden" value="" name="testing" id-"testing" />
document.getElementById("testing").value = 'your value';
this is one of the method .
Upvotes: -1
Reputation: 151
Suppose you have a hidden input with id XXX, if you want to assign a value to the following
<script type="text/javascript">
$(document).ready(function(){
$('#XXX').val('any value');
})
</script>
Upvotes: 12
Reputation: 6941
You don't need to set name , just giving an id is enough.
<input type="hidden" id="testId" />
and than with jquery you can use 'val()' method like below:
$('#testId').val("work");
Upvotes: 2
Reputation:
You should use val
instead of value
.
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('input[name="testing"]').val('Work!');
});
</script>
Upvotes: 149
Reputation: 2928
To make it with jquery, make this way:
var test = $("input[name=testing]:hidden");
test.val('work!');
Or
var test = $("input[name=testing]:hidden").val('work!');
See working in this fiddle.
Upvotes: 5
Reputation: 1891
var test = $('input[name="testing"]:hidden');
test.val('work!');
Upvotes: 8
Reputation: 371
This worked for me:
$('input[name="sort_order"]').attr('value','XXX');
Upvotes: 37