faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 35 people (46%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do you check for the existence of a text box on a form?

Aug 11th, 2006 16:33
David Alden, Brian Licci,


<html>
<script type="text/javascript" language="javascript">
	function areThereTextBoxes(){
		var elements = document.getElementsByTagName('INPUT');
		var isText = "no";
		for(var i = 0; i < elements.length; i++){
			if(elements[i].type=="text"){
				isText="yes";
			}
		}
		alert(isText);
	}
</script>
	<form name="thisForm">
		<input type="text" name="thisText">
		    
		<textarea name="thisTextarea" >Some sample 
text</textarea>
		<br>
		<br>
		<input type="button" value="Are there Text Boxes on 
this page?" onclick="areThereTextBoxes()">
	</form>
</html>