Trying to do something if the input value contains a certain word but this doesn’t work:
var formMain = $('#MainForm :input[name="Search"]');
if ((formMain).value.indexOf('word') >= 0) {
alert('HAS THIS WORD IN IT!');
Example Form:
<form onsubmit="return OnSubmitSearchForm(event, this);" action="/searchresults.asp" id="MainForm" name="MainForm" method="post" class="search_results_section">
<input type="hidden" value="word" name="Search">
<input type="hidden" value="" name="Cat">
</form>
Your title mentions
val()but you’re not actually using it.formMainis a jquery object and has novalue, you should useval().Also note that
formMainis a misleading variable name as it is not the main form but rather a jquery object which contains the search input.