1ページに、検索用の2つのフォームがあります。
<form class="search-panel" method="post" action="" onsubmit="return searchRedirect(this)">
<input type="test" name="searchFor" />
<div class="additional-search-button"></div>
<div id="additional-search-box">
<div class="as-cont">
Books<input type="radio" name="category" value="Books" checked="1" /><br/>
School<input type="radio" name="category" value="School" /><br/>
Music<input type="radio" name="category" value="Music" />
</div>
</div>
<input type="submit" name="search" />
</form>
<form class="search-panel" method="post" action="" onsubmit="return searchRedirect(this)">
<input type="test" name="searchFor" />
Games<input type="radio" name="category" value="Games" checked="1" />
<input type="submit" name="search" />
</form>
私の問題は、searchRedirectでGamesの検索をクリックすると、Books、School、またはMusicがチェックした場合に常にアラートを出すことです。
それが私のjavascript関数です:
function searchRedirect(form) {
alert($(form['category']+':checked').val());
if($(form['category']+':checked').val() == 'Форум')
window.location.href = '/forum/search.php?keywords='+form['searchFor'].value;
else {
window.location.href = '/Search/'+$(form['category']+':checked').val()+'/'+form['searchFor'].value;
}
return false;
}
クリックしてゲームを検索する場合(クリックして本、学校、音楽のみを検索する場合)、クリックしてゲームのみを検索する場合に必要です。ただし、ゲームの検索フォームでは、常に最初のフォームのチェックボタンを使用するようになりました。