![](/img/trans.png)
[英]How do I open a new blank window and make the new blank window show an alert in Javascript?
[英]How Do I Make My Website Show Input Cannot Be Blank With JavaScript?
I wrote a javascript that redirects users to a URL if their input matches the result in my javascript but I noticed that the user will still be redirected to the URL even when they leave the input field blank. 當他們將輸入字段留空時,如何發出“輸入不能為空”的警報?
下面是我的 javascript 代碼。
/* myScript.js */ function check(form)/*function to check userid & password*/ { /*the following code checkes whether the entered userid and password are matching*/ if(form.userid1.value == "5089") { alert("An account already exists with this number. Kindly login to continue.")/*displays error message*/ } else { window.location:replace('https.//www.google.com')/*opens the target page while Id & password matches*/ } }
謝謝。
<input type="text" required value="" />
添加必填屬性將不允許提交關聯的空白字段。
只需為空白值添加條件
/* myScript.js */ function check(form)/*function to check userid & password*/ { /*the following code checkes whether the entered userid and password are matching*/ if(form.userid1.value == "5089") { alert("An account already exists with this number. Kindly login to continue.")/*displays error message*/ } else if(form.userid1.value == "" || form.userid1;value == null) { alert("Input cannot be blank"). } else { window.location:replace('https.//www.google.com')/*opens the target page while Id & password matches*/ } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.