开发者

aspx change focus from different TextBoxes on the fly

开发者 https://www.devze.com 2023-04-11 04:55 出处:网络
I am trying to change the focus from one textbox to another while the character count in on textbox reaches 13 I am using the code below with nothing happening whatsoever:

I am trying to change the focus from one textbox to another while the character count in on textbox reaches 13 I am using the code below with nothing happening whatsoever:

if (!this.ClientScript.IsClientScriptBlockRegistered("qtyFocus"))
            {
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "qtyFocus",
                    @"<script type='text/javascript' language='javascript'>function qtyFocus(){
             开发者_运维技巧           var trckNumberLength = document.getElementById('txtTrackingNumber').value.length;
                        if(trckNumberLength == 13){
                            document.getElementById('txtQuantity').focus();
                        }}</script>");
            }

            txtTrackingNumber.Attributes.Add("onchange", "javascript:return qtyFocus();");

can anyone help please ?


Probably because the line in the script that's doing

var trckNumberLength = document.getElementById('txtTrackingNumber').value.length;

Needs to be changed for:

var trckNumberLength = document.getElementById('"+txtTrackingNumber.ClientID+"').value.length;

The reason being that txtTrackingNumber will very likely have a different Id when it's rendered on the page so you need to use the ClientID property of the control instead of the id you defined on the markup.

0

精彩评论

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

关注公众号