<html>
<head>
<script>
function testing(){
var search1 = document.forms['tfnewsearch']['search1'].value;
if(search1 == null || search1 == "")
{
alert("Error! Please type in something");
isValid = false;
}
}
</script>
</head>
<form name= id="tfnewsearch" method="post" action="" onsubmit ="return testing();">
<p><input type="text" class="tftextinput" id="search1" size="21" maxlength="120"/>
<input type="submit" value="search" class="tfbutton"/></p>
</form>
<body>
</body>
</html>
所以我试图在这里做的是,如果用户没有输入任何相当于空值的东西,但是我不明白为什么它不显示弹出窗口,则显示警告弹出窗口。我认为我的功能没有错误,
答案 0 :(得分:0)
以下是:
JS:
function testing(){
var search1 = document.getElementById('search1').value;
if(search1 == undefined || search1 == ""){
alert("Error! Please type in something");
isValid = false;
}
}
HTML:
<form name="searchForm" id="tfnewsearch" method="post" action="http://google.com" onsubmit ="testing();">
<p><input type="text" class="tftextinput" id="search1" size="21" maxlength="120"/>
<input type="submit" value="search" class="tfbutton"/></p>
</form>