戻る

フォームの内容変更を感知する

HTML5

<!DOCTYPE html>
<html lang="ja-JP">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,user-scalable=yes,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.5">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
window.addEventListener("load",function(){
	document.querySelector("select").addEventListener("change",function(){
		document.querySelector("span").innerText = document.querySelector("select").value;
	});
});
</script>
<body>
申し込み者:
<select>
	<option value="お名前">個人</option>
	<option value="会社名">法人</option>
</select>
<p><span>お名前</span><input type="text"></p>
</body>
</html>

jQuery

<!DOCTYPE html>
<html lang="ja-JP">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,user-scalable=yes,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.5">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function(){
	$("select").change(function(){
		$("span").text($(this).val());
	});
});
</script>
<body>
申し込み者:
<select>
	<option value="お名前">個人</option>
	<option value="会社名">法人</option>
</select>
<p><span>お名前</span><input type="text"></p>
</body>
</html>

inserted by FC2 system