<html> <head> <title>ThaiCreate.Com Tutorial</title> <script language="JavaScript"> function fncCheck() { var elm; ele_text = document.frmMain.getElementsByTagName('input'); for( i=0, elm; elm=ele_text.item(i++); ) { if (elm.getAttribute('type') == "text") { alert("elm.name=" + elm.name); alert("elm.value=" + elm.value); } } } </script> </head> <body> <form name="frmMain" action="" method="post"> Text 1<input type="text" name="txt1" value=""> <br> Text 2<input type="text" name="txt2" value=""> <br> <input type="button" name="btnCheck" value="Check" OnClick="fncCheck();"> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com Tutorial</title> <script language="JavaScript"> function fncCheck() { var elm; ele_text = document.frmMain.getElementsByTagName('input'); for( i=0, elm; elm=ele_text.item(i++); ) { if (elm.getAttribute('type') == "text") { alert("elm.name=" + elm.name); alert("elm.value=" + elm.value); } } ele_hidden = document.frmMain.getElementsByTagName('hidden'); for( i=0, elm; elm=ele_hidden.item(i++); ) { if (elm.getAttribute('type') == "hidden") { alert("elm.name=" + elm.name); alert("elm.value=" + elm.value); } } ele_textarea = document.frmMain.getElementsByTagName('textarea'); for( i=0, elm; elm=ele_textarea.item(i++); ) { if (elm.getAttribute('type') == "textarea") { alert("elm.name=" + elm.name); alert("elm.value=" + elm.value); } } ele_select = document.frmMain.getElementsByTagName('select-one'); for( i=0, elm; elm=ele_select.item(i++); ) { if (elm.getAttribute('type') == "select-one") { alert("elm.name=" + elm.name); alert("elm.value=" + elm.value); } } } </script> </head> <body> <form name="frmMain" action="" method="post"> Text 1<input type="text" name="txt1" value=""> <br> Text 2<input type="text" name="txt2" value=""> <br> <input type="button" name="btnCheck" value="Check" OnClick="fncCheck();"> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท