开发者

Javascript cannot find hidden Field in ASP.NET?

I am trying save the disabled property value of a hidden field to track the disabled state of a button between postbacks, with the following javascript

function TrackState(buttonID)
{
   var trackingField = document.getElementById("_tracking" + buttonID);

    return false; // prevent default action
}

HTML

<input type="hidden" name="_trackingButton1" value="true" />

but开发者_运维百科 trackingField seems to be null each time, what is going wrong here


You need to assign the id property of your element (not just name) and it should work like this:

<input type="hidden" id="_trackingButton1" name="_trackingButton1" value="true" />

I hope this helps.


In your function

function TrackState(buttonID) { }

what is the buttonID value exactly. I hope it is "Button1". And as the function says getElementById the input has the property id with the same value.


The getElementById() method specifically looks for id values:

<input type="hidden" id="_trackingButton1" name="_trackingButton1" value="true" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜