I get value from checkFields
method and then I assign it to hidden variable searchValidate
. The value of atleastOneFilled
will be true
or false
.Below is the code
var atleastOneFilled = checkFields($("#searchForm"));
alert('atleastOneFilled' + atleastOneFilled );
$('#searchValidate').val(atleastOneFilled);
But the value is not getting set to searchValidate
. The alert displays the correct value but still not assigned to searchValidate
. Is it something a wrong way of assigning to .val()
HTML:
<input type="hidden" value="" th:name="searchValidate"/>
I get value from checkFields
method and then I assign it to hidden variable searchValidate
. The value of atleastOneFilled
will be true
or false
.Below is the code
var atleastOneFilled = checkFields($("#searchForm"));
alert('atleastOneFilled' + atleastOneFilled );
$('#searchValidate').val(atleastOneFilled);
But the value is not getting set to searchValidate
. The alert displays the correct value but still not assigned to searchValidate
. Is it something a wrong way of assigning to .val()
HTML:
<input type="hidden" value="" th:name="searchValidate"/>
#searchValidate
?
– Alex McMillan
Commented
Jun 9, 2015 at 3:40
#searchValidate
?
– Felix Kling
Commented
Jun 9, 2015 at 3:41
you need to use a different jquery selector:
$('input[name="searchValidate"]').val(atLeastOneField);
the #
signifies the id
property of an element
The issue is happening because you are using id selector in jQuery to set the value and the input element is missing the id attribute. So please change the html as shown below and it will work
<input type="hidden" value="" id="searchValidate" th:name="searchValidate"/>
I think you can't select when attributes contain ":"
you need to use foreach loop and match attributes .
var atleastOneFilled = checkFields($("#searchForm"));
alert('atleastOneFilled' + atleastOneFilled );
$( "input[type='hidden']" ).each(function(){
if($( "input" ).attr("th:name")="searchValidate")
{
$('#searchValidate').val(atleastOneFilled);
}
});
maybe try
$('#searchValidate').text(atleastOneFilled);
instead of
$('#searchValidate').val(atleastOneFilled);