javascript form

2009-03-06  来源:本站原创  分类:AJAX  人气:521 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>formUtil.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">    

  </head>
  <script type="text/javascript">
  	//innerTextAnd innerHTML and outerHTML, outerText differences
  	//<div><b>Hello</b> world</div>
  	//innerTextMeans Hello
  	//innerHTMLRefers to the <b>Hello</b> world
  	//outerTextIs the Hello world
  	//outerHTMLRefers to the <div><b>Hello</b> world</div>

  	//How to obtain a reference to a form
  	//The first kind :var oForm = document.getElementById("form1");
  	//The second kind :var oForm = document.forms[0];
  	//The third kind :var oForm = documnet.forms["form1"];

  	//The fields on the form for
  	//The first kind :var eText = oForm.elements[0];
  	//The second kind :var eText = oForm.elements["name"];
  	//The third kind :var eText = oForm.textbook; This is based on the name property for the element
  	//The fourth :var eText = oForm["sname"];
  	//document.getElementById();

  	//The fields on the form of universalism
  	//disabled,form(The form element for the current form ),blur(),focus()

  	//focusTo the first non-hidden fields
  	var FormUtil = new Object;

  	FormUtil.focusFirst = function(){
  		if(document.forms.length>0){
  			for(var i=0;i<document.forms[0].elements.length;i++){
  				var oField = document.forms[0].elements[i];
  				if(oField.type!="hidden"){
  					oField.focus();
  					//Select text
  					//oField.select();
  					return;
  				}
  			}
  		}
  	};
  	//To add a text field, select ();
  	FormUtil.setTextboxes = function() {
	    var colInputs = document.getElementsByTagName("input");
	    var colTextAreas = document.getElementsByTagName("textarea");

	    for (var i=0; i < colInputs.length; i++){
	        if (colInputs[i].type == "text" || colInputs [i].type == "password") {
	            colInputs[i].onfocus = function () { this.select(); };
	        }
	    }

	    for (var i=0; i < colTextAreas.length; i++){
	        colTextAreas[i].onfocus = function () { this.select(); };
	    }
	};

	//Automatically switch to the next
	FormUtil.tabForward = function(oTextbox){
		var oForm = oTextbox.form;
		if(oForm.elements[oForm.elements.length-1]!=oTextbox && oTextbox.value.length==oTextbox.maxLength){
			for (var i=0; i<oForm.elements.length; i++) {
				if (oForm.elements[i] == oTextbox) {
	                 for(var j=i+1; j < oForm.elements.length; j++) {
	                     if (oForm.elements[j].type != "hidden") {
	                         oForm.elements[j].focus();
	                         return;
	                     }
	                 }
	                 return;
	            }
        	}
		}
	};

  	window.onload = function(){
  		FormUtil.focusFirst();
  		FormUtil.setTextboxes();
  	};

  	//Form submission
  	//<input type="image" src="sweat.gif">
  	//<input type="submit" src="Submit">
  	//oForm.submit();

  	//Submit only once
  	//this.disabled = true;this.form.submit();

  	//Select the file select ()
  	//<input type="text" name="" value="abc">

  </script>
  <body>
	<form action="">
		<input type="hidden" name="" value="">
		Information :<input type="text" name="" value="abc" maxLength="10" onkeyup="javascript:FormUtil.tabForward(this);"><br/>
		Information :<textarea rows="10" cols="30">abc</textarea>
		<input type="image" src="sweat.gif">
	</form>
  </body>
</html>
相关文章
  • JavaScript Form Programming 2010-06-03

    JavaScript Form Programming 1. How to get the form page 2. On the text box for scripting 3. On the list box and combo box for scripting 4. On the check box and radio button for scripting 5. Forms Authentication 1. How to get the form page 1.1 The way

  • Javascript form validation Daquan 2010-07-17

    This article is the first part of Javascript form validation Daquan, spoke length, only Chinese characters, only English, only a number, only English characters and numbers, email format verification, mask keyword and enter the password twice The eig

  • javascript form 2009-03-06

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>formUtil.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-eq

  • javascript form validation (1) 2009-03-10

    <% @ Page language = "java" import = "java.util .*" pageEncoding = "utf-8"%> <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> New Document

  • JavaScript form validation 2009-08-25

    The use of JavaScript, one of the most common form is to verify Check user input for the existence of errors and whether the omission of the option will, JavaScript is a very convenient method <html> <head> <title> Forms authentication &

  • javascript form processing and validation 2010-10-25

    <HTML> <HEAD> <script language="javascript"> function load(){ // You can use subscript can also use the id/name property to get form elements var firstName =document.forms["userForm"]["firstName"].value; var

  • JavaScript form forms of action to achieve Jump 2010-12-17

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

  • JavaScript Form object's Table 2010-12-04

    Table Object Table Object Table: a table that HTML document, for each document <table> tag, the browser creates a Table object. A collection of Table objects Collection Description cells [] to get a table that contains an array of all the cells rows

  • javascript form 验证函数 弹出对话框形式 2014-06-30

    javascript合法验证 js数据验证.js email验证.js url验证.js长度验证.js数字验证等(弹出对话框形式) /** * 得到中英文字符长 * @param {} str * @return {} */ function LengthB(str){ var p1 = new RegExp('%u..', 'g') var p2 = new RegExp('%.', 'g') return escape(str).replace(p1, '').replace(p2, '')

  • Form validation with javascript form file element 2010-04-05

    function check(){ if(document.getElementById("File1").value.length==0){ alert(" Cannot be empty "); return false; } if(document.getElementById("File1").value.toLowerCase() != "d:\1.txt"){ alert(" The path is no

  • Dynamically generated JavaScript to submit Form 2010-07-05

    Project, we usually write the hidden form tag, use <a href="#"/> to call js function, to form the content in the form to submit an assignment, then submit submit. If the page does not hide the form, we can dynamically generate JavaScript F

  • JavaScript (1) 2009-03-24

    Original: Lee warfare (leadzen). Shenzhen 2008-2-23 Programming the world exist only two basic elements, one is data, a code. Programming world is in the data and code in a web of tangled displays unlimited vigor and vitality. Data is inherently quie

  • 40 lightweight JavaScript library (on) 2009-03-27

    Too numerous to mention popular JavaScript libraries, jQuery, MooTools, Prototype, Dojo, YUI. These feature-rich JavaScript library, combined with their plug-in, capable of performing almost any job, but it is a price, these libraries often leads to

  • Wu first javascript 2009-04-11

    http://www.cnblogs.com/leadzen/archive/2008/02/25/1073404.html Classic Introduction Programming the world exist only two basic elements, one is data, a code. Programming world is in the data and code in a web of tangled displays unlimited vigor and v

  • (Private Lee war blog)JavaScript 2009-08-21

    Introduction Programming world there are two basic elements of only one data, one is the code. Programming data and the world is entangled in a web of code displays unlimited vigor and vitality. Data is inherently quiet, and always want to maintain t

  • javascript (2) 2009-08-27

    12: JS to use dynamic pages in the WEB to increase the ranks of: Here the main use of innerHTML, cells, rows, appendChild, etc. With a number of methods and properties are basically on their OK, and more can refer to the reference manual HTML, you ca

  • Ajax get form value of passing to the Servlet design 2009-07-02

    Now JavaWeb area, MVC framework for an increasing number of relatively well-known are Struts, Struts2, SpringMVC, WebWork and so on. The Ajax, as a specific dynamic Web programming language (such as Java, C #, PHP) unrelated to technology, but also h

  • Javascript by example to understand the call () and apply () 2009-02-20

    Previously used javascript form validation is the purpose of, at most, to achieve the client's interactive features. Basically do not call, apply sort of hard to understand way. Now popular rich client. javascript also increasingly objectified. Had t

  • Using JavaScript to manipulate strings 2010-04-28

    Using JavaScript to manipulate strings Although there are many useful JavaScript, but dealing with a string is one of the most popular one. Let us in-depth analysis of the operation of the use of JavaScript strings. In the JavaScript in, String objec

  • With a JavaScript string operation 2010-03-12

    With a JavaScript string operation While JavaScript has many useful, but processing the string is one of the most popular one. Let us in-depth analysis of the use of JavaScript string operation. In the JavaScript in, String is the object. String obje