<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>form部品の種類を判別</title> <link href="/gudon/css/default.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>form部品の種類を判別</h1> <hr /> <form name="form1"> <input name="textbox1" type="text" value="テキストボックス"/> <input name="button1" type="button" value="ボタン" onclick="button1_onclick();"/> </form> <script type="text/javascript"> function button1_onclick() { var inputs = document.form1.getElementsByTagName("input"); for(var i = 0; i < inputs.length; i++) { if(inputs[i].type=="text"){ alert(inputs[i].name+"はテキストボックス"); }else if (inputs[i].type=="button") { alert(inputs[i].name+"はボタン"); }; } } </script> </body> </html>