2022年4月3日 星期日

[研究][ASP.NET][JavaScript]送出表單時檢查,彈出alert對話盒視窗

[研究][ASP.NET][JavaScript]送出表單時檢查,彈出alert對話盒視窗

2022-04-01

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

送出表單時檢查 Test.html


<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
  let x = document.forms["form1"]["cname"].value;
  if (x == "") {
    alert("Name must be filled out");
    return false;
  }
}
</script>
</head>
<body>

<h2>JavaScript Validation</h2>

<form name="form1" action="/action_page.php" onsubmit="return validateForm()" method="post">
  Name: <input type="text" name="cname">
  <input type="submit" value="Submit">
</form>

</body>
</html>


********************************************************************************

送出表單時檢查 Default3.aspx


<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Default3.aspx.cs" Inherits="WebApplication1.Default3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script>
        function SubmitForm() {
            var v1 = document.getElementById('TextBox1').value;
            if (v1 == "") {
                alert("Require1!");
                return false;
            }
            var v2 = document.getElementById('TextBox2').value;
            if (v2 == "") {
                alert("Require2!");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
            <asp:Button ID="Button1" OnClientClick="javascript:return SubmitForm();" runat="server" Text="Button" />            
        </div>
    </form>
</body>
</html>



********************************************************************************

(完)

相關

javascript - Show alert when focusout, only once - Stack Overflow
https://stackoverflow.com/questions/21579194/show-alert-when-focusout-only-once

.focusout() | jQuery API Documentation
https://api.jquery.com/focusout/

.blur() | jQuery API Documentation
https://api.jquery.com/blur/

jQuery focusout() Method
https://www.w3schools.com/jquery/event_focusout.asp

jQuery - focusin/focusout/focus/blur事件的區別與不同
https://www.cnblogs.com/jie888/p/9140332.html

https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/625398/

http://m.blueshop.com.tw/Thread.aspx?tbfumsubcde=BRD20170915103507DWF

相關

[研究][ASP.NET]JavaScript alert對話盒視窗彈出位置測試
https://shaurong.blogspot.com/2022/04/aspnetjavascript-alert.html

[研究]ASP.NET + JavaScript Alert 彈出視窗換行測試 vs 彈出視窗沒出現研究
https://shaurong.blogspot.com/2022/03/javascript-alert.html

[研究]HTML, CSS, JavaScript, jQuery, jQuery UI, Bootstrap 彈出對話盒視窗
https://shaurong.blogspot.com/2020/11/html-css-javascript-jquery-jquery-ui.html

[研究]]JavaScript] 用 orangehill / bootstrap-session-timeout 做 Session Time Out 前 N 秒自動彈出對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-orangehill-bootstrap-session.html

[研究][JavaScript] 用 session-timeout.js 做 Session Time Out 前 N 秒自動彈出對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-session-timeoutjs-session.html

[研究][JavaScript]Master Page 用 idle-timer.js 做 Session Time Out 前 N 秒自動彈出倒數計時對話盒視窗
https://shaurong.blogspot.com/2020/11/javascriptcaspnetwebform-master-page.html

[研究][JavaScript] 用 idle-timer.js 做 Session Time Out 前 N 秒自動彈出倒數計時對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-idle-timerjs-session-time.html

[研究][JavaScript] 用 timeout-dialog.js 做 Session Time Out 前 60 秒自動彈出倒數計時對話盒視窗
https://shaurong.blogspot.com/2020/11/javascript-timeout-dialogjs-session.html

[研究][C#] [ASP.NET] [JavaScript] 彈出視窗 (對話盒)
https://shaurong.blogspot.com/2020/04/c-aspnet-javascript.html

[研究][C#] [ASP.NET] [JavaScript] 彈出視窗
https://shaurong.blogspot.com/2017/06/c-aspnet-javascript.html


沒有留言:

張貼留言