検索フォームにて、テキストボックスに入力された値(半角数字)をそのままアラートとして表示したいです。
半角数字以外が含まれると「エラー」とアラートで表示されるようにしております。
よろしくお願いいたします。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content=" ">
<meta name="description" content=" ">
<meta http-equiv="content-style-type" content="text/css">
<meta http-equiv="content-script-type" content="text/javascript">
<link rel="stylesheet" href="style.css">
<link href="./style.css" rel="stylesheet" type="text/css">
<title> </title>
<script type="text/javascript">
//関数 checkText の定義 (引数:テキストインプット)
function checkText(txt_obj){
//テキストインプット内の入力値を変数化
var str ="エラー"
//入力値に 0~9 以外があれば
if(str.match(/[^0-9]+/))
{alert(str);}
}
</script>
</head>
<body>
<div class="form">
<form action="cgi-bin/example.cgi" method="post" onkeyup="checkText(this)">
<p>検索したいキーワードを入力してください。</p>
<input type="text" name="search" placeholder="キーワードを入力" value="">
<input type="submit" name="submit" value="検索">
</form>
</div>