0
我做的PHP是文字框爲空值時,它會打開一個alertbox(我使用javascript在這裏)PHP的JavaScript alertbox必須點擊2次拿給
這是我的代碼
<?php
include('config.php');
if(isset($_POST['submit'])){
$username=$_POST['username'];
?>
<script>
function validate(){
if(document.forms[0].username.value==""){
window.alert("You must enter both values");
return false;
}
}
</script>
<?php
}
?>
<html>
<div><p>Member Profile</p>
<form action="testing.php" method="POST" onsubmit="return validate();">
Username<br>
<input class="user" type="text" name="username" id="username" /><br>
<input type="submit" name="submit" value="register" />
</form>
</div>
</html>
的問題是我之前的警報顯示點擊2次
請幫我解決這個問題