views:

209

answers:

3

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

+3  A: 

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.

James
It won't get posted back unless it also has a `name` property.
tvanfosson
@tvanfosson - good point, i've updated my post.
James
+1  A: 

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.

Undefined
+1 my thought initially as well, I was just about to type it out and saw you got it covered
curtisk
+1  A: 

The getElementById() method specifically looks for id values:

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