开发者

if user pastes 32 characters into the license text-box first split textbox

if user pastes 32 characters into the license text-box first split textbox, the method will place 8 characters into each of the 4 text boxes

see i have 4 text box ... max length (8)

<input type = "text" size = "8" maxlength="32" name = "LicenseNumber1" 
id="LicenseNumber1">

<input type = "text" size = "8" maxlength="32" name = "LicenseNumber2" 
id="LicenseNumber2">

<input type = "text" size = "8" maxlength="32" name = "LicenseNumber3" 
id="LicenseNumber3">

<开发者_如何转开发;input type = "text" size = "8" maxlength="32" name = "LicenseNumber4" 
id="LicenseNumber4">

& my license is 32 characters like 06e1823681f48e2f013904403b33ff08 now if i paste the whole 32 character in my first test box i.e. LicenseNumber1 then i

want other three textbox wil be automatic fill bcause(8*4=32)


Here's a starting point. It works in all major browsers. You may want to extend it to handle input in the other three input boxes.

Code:

var inputs = [
    document.getElementById("LicenseNumber1"),
    document.getElementById("LicenseNumber2"),
    document.getElementById("LicenseNumber3"),
    document.getElementById("LicenseNumber4")
];

function handleInput(input) {
    var allText = input.value, inputToFocus = input;
    for (var i = 0, len = inputs.length; i < len; ++i) {
        if (allText.length > 0) {
            inputs[i].value = allText.slice(0, 8);
            inputToFocus = inputs[i];
            allText = allText.slice(8);
        }
    }
    window.setTimeout(function() {
        inputToFocus.focus();
    }, 1);
}

// IE 9 and non-IE
inputs[0].oninput = function() {
    handleInput(this);
};

// IE <= 8
var handlingValueChange = false;

inputs[0].onpropertychange = function() {
    if (window.event.propertyName == "value" && !handlingValueChange) {
        handlingValueChange = true;
        handleInput(this);
        handlingValueChange = false;
    }
};

jsFiddle:

http://jsfiddle.net/DGzCx/6/


Live Demo

$("#license").keyup(function() {
    if ($(this).val().length == 32) {
        var reg = new RegExp("(\\w{8})", 'g');
        $(this).val($(this).val().replace(reg, "$1\n"));
    }
});


Well, here is an example.
It isn't perfect, but it is a good base.
http://jsfiddle.net/mazzzzz/nRHM3/4/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜