☆☆ 新着記事 ☆☆

2018年6月17日日曜日

Javascript 入力フォームのバリデーション




js スクリプト
var loan_amt = document.loan_form.loan_amt.value;
 var months = document.loan_form.months.value;
 var rate = document.loan_form.rate.value;
 var extra = document.loan_form.extra.value;

 if(loan_amt <= 0 || isNaN(Number(loan_amt))){
  alert("please enter a valid loan amount.");
  document.loan_form.loan_amt.value = "0";
  }

 else if (months <=0 || parseInt(months) != months){
  alert("please enter a valid number of months.");
  document.loan_form.months.value = "0";
 }

 else if (rate <= 0 || isNaN(Number(rate))){
  alert("please enter a valid interest rate.");
  document.loan_form.loan_amt.value = "0";
  }





b

0 件のコメント:

コメントを投稿