フォーム送信時に空欄を確認(文字入力ダイアログ prompt)
<html> <head> <title>フォーム送信時に空欄を確認</title> <script language="JavaScript"> <!-- function check() { if(document.form1.name.value == "") { name = prompt("名前を入力してください",""); if(name && (name != "null")) { document.form1.name.value = name; } else { return false; } } if(document.form1.mail.value == "") { mail = prompt("メールアドレスを入力してください",""); if(mail && (mail != "null")) { document.form1.mail.value = mail; } else { return false; } } if(document.form1.text.value == "") { text = prompt("本文を入力してください",""); if(text && (text != "null")) { document.form1.text.value = text; } else { return false; } } } //--> </script> </head> <body> <form name="form1" action="../../sample/sample.cgi" method="post" onSubmit="return check()"> 名前<br> <input type="text" name="name" size="50"><br> <br> メールアドレス<br> <input type="text" name="mail" size="50"><br> <br> 本文<br> <textarea name="text" cols="50" rows="10"></textarea><br> <br> <input type="submit" value=" 送 信 "> </form> </body> </html>
〔 実行する 〕