私は長いフォームを持っているので、内部にデータがある入力とテキストエリアの数を数える必要があります。フォーム内にデータがある入力とテキストエリアの数を表す数値を表示する入力フィールドが必要です。
私はjqueryまたはPHPが好きです。
そこに例や提案はありますか?
ありがとう。エリック
jQueryを使用すると、これを使用できます
var number = $('#form').find('input, textarea')
// filter out every empty input/textarea
.filter(function() { return $(this).val() == ''; })
.length;
データを持つフィールドの数でdivを実行および更新するonkeypress関数を実行できます。
私の頭の上からですが、多分:
function tallyFields() {
var totalFilledFields = 0;
var fieldAVal = document.getElementByID("fieldA").value;
// add more fields here the same way
if(fieldAVal.length > 0) {
totalFilledFields++;
}
// check more fields here the same way and increment the same var
document.getElementByID("yourTotalDiv").innerHTML=totalFilledFields;
}
各フォームフィールドのキープレスでこの関数を割り当てると、うまくいく可能性があります。
これでうまくいくはずです:
$(".myform :input").length;