Text Object Select and Focus : JavaScript DHTML examples (example source code) » Form Control » TextField

JavaScript DHTML










Java Products
Java Articles
JavaScript DHTML Home  »   Form Control   » [  TextField  ]   

 
Text Object Select and Focus

Please note that some example is only working under IE or Firefox.

/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

Publisher: John Wiley & Sons CopyRight 2001
ISBN: 0764533428
*/

<HTML>
<HEAD>
<TITLE>Text Object Select/Focus</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// general purpose function to see if a suspected numeric input is a number
function isNumber(inputStr) {
    for (var i = 0; i < inputStr.length; i++) {
        var oneChar = inputStr.charAt(i)
        if (oneChar < "0" || oneChar > "9") {
            alert("Please make sure entries are integers only.")
            return false
        }
    }
    return true
}
function checkNumeric(fld) {
    var inputStr = fld.value
    var fldName = fld.name
    var formName = fld.form.name
    if (isNumber(inputStr)) {
        // statements if true
    else {
        setTimeout("doSelection(document." + formName + ". " + fldName + ")"0)
    }
}
function doSelection(fld) {
    fld.focus()
    fld.select()
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="entryForm" onSubmit="return false">
Enter any positive integer: <INPUT TYPE="text" NAME="numeric"><P>
<INPUT TYPE="button" VALUE="Verify" onClick="checkNumeric(this.form.numeric)">
</FORM>
</BODY>
</HTML>
Related examples in the same category
1.  TextField focus and select all
2.  Show TextField value in Dialog
3.  TextField focus, blur, and click action
4.  Display textfield value in new page
5.  JavaScript Loan Calculator
6.  Another TextField jump
7.  TextField get Focus and clear content
8.  Validate an input field with minimum and maximum values
9.  Validate an field with a maximum number of characters
10.  Select the textfield and focus
11.  Focus an input field
12.  Jump to the next field
13.  Get textfield value
14.   Methods and Properties of the Text Object
15.  Selecting Text Upon Focus
16.  assign a default value to a Text object
17.  Compound Interest Calculator
18.  Resetting a Text Object to Default Value
19.  Getting and Setting a Text Object's Value
20.  Passing a Text Object (as this) to the Function
21.  Data Validation via an onChange event Handler
22.  Add textfield dynamically into HTML
23.   Firing the onSame Event (FireFox)
24.  Numerals Only
25.  Letter only, yes no only textfield
26.  Auto focus textfield
27.  Block enter textfield
28.  If the textfield has been changed








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.