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"/>
Share
Improve this question
edited Jun 9, 2015 at 3:43
Java_User
asked Jun 9, 2015 at 3:38
Java_UserJava_User
4753 gold badges12 silver badges30 bronze badges
5
- What does your html look like? – Jesse Kernaghan Commented Jun 9, 2015 at 3:39
-
What type of field is
#searchValidate
? – Alex McMillan Commented Jun 9, 2015 at 3:40 -
What kind of element is
#searchValidate
? – Felix Kling Commented Jun 9, 2015 at 3:41 - How do you check that it is not assigned? – Kirill Slatin Commented Jun 9, 2015 at 3:42
- I have edited the question with HTML – Java_User Commented Jun 9, 2015 at 3:44
4 Answers
Reset to default 2you 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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745662301a4638910.html
评论列表(0条)