I want to toggle the value of a hidden input, between advanced and normal? But the below script doesn’t work, nothing happens.
$('#advancedLink').click(function () {
$("#searchType").val($(this).text() == 'normal' ? 'advanced' : 'normal');
return false;
});
However, if I switch place of normal and advanced it will work one time, but it won’t switch back to normal if I click again.
$('#advancedLink').click(function () {
$("#searchType").val($(this).text() == 'normal' ? 'normal' : 'advanced');
return false;
});
But this last way seems rather unintuitive to me. Any ideas?
EDIT
This is the rendered HTML
<div>
<div class="left" id="searchControl">
<a id="advancedLink" href="#">Advanced search</a><br>
</div>
<input type="hidden" value="normal" name="searchType" id="searchType">
</div>
You’re checking the value of the link but setting the value for the text box. Since the value of the link never changes, the text box value does not change either.
Here’s a fiddle : http://jsfiddle.net/GKfWB/