javascript form submit 檢查問題

寫 javascript function 來檢查 form submit 相當常見,也有相當多的寫法,以下是一個很好的參考範例:

function check() {

var valid=true;

if ( document.forms[0].name.value == null || document.forms[0].name.value == “” ) {
valid=false;

alert(“Please fill your name!”);

}

.

.

if ( valid  ) {

document.forms[‘register’].submit();

return true;

} else {

return false;

}

html form 寫法如下:

<form name=”registerForm” action=”register.php” method=”post” onsubmit=”return check()“>

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...