私のウェブページには、それぞれのドロップダウンで「n」行を配置するこのコードがあります。すべてのドロップダウンに値が含まれている場合にのみ送信ボタンを有効にする方法はありますか?つまり、ドロップダウンが空であってもボタンを有効にするべきではありません。また、私は最初のクリック後に送信ボタンを無効にしたい。whileループ内のすべてのドロップダウンがヌルでない場合にのみサブミットボタンを有効にする方法
次のコードを試しましたが、動作しません。
$rowIndex = 0;
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
<form>
<div>
<select name = error_type id='error_type$rowIndex' class='picker'>
<option disabled selected value> -- select an option -- </option>
<option value=2_Stage_Error>2_Stage_Error</option>
<option value=BG_Error>BG_Error</option>
</select>
</div>
$rowIndex++;
}
<input type='submit' value='SUBMIT' id='submit' onclick=report_submit()disabled
= true />
</form>
それは、ユーザーがフォームを送信する前に値を選択する必要がある指定するSELECT文を使用して、JS
<script type= "text/javascript">
$(function() {
$('.picker').on('change', function() {
var $sels = $('.picker option:selected[value=""]');
$("#submit").attr("disabled", $sels.length > 0);
}).change();
});
</script>
まず、代わりに 'attr' – Rayon
https://jsfiddle.net/rayon_1990/dvphbf5f/1/ – Rayon
あなたが意図的に外にあなたのwhileループを入れなかったの' jQuery.prop'使用フォーム? – Beginner