0

I am using javascript to get the value of a hiddenfield

<script type="text/javascript">
        $(function() {
            var newYear = document.getElementById('HF');
            alert('hehe' + newYear);
            $('#countdown').countdown({ until: newYear, format: 'DHMS', layout:
'<div id="timer">' + '<hr />' +
    '<div id="timer_days" class="timer_numbers">{dnn}</div>' +
    '<div id="timer_hours" class="timer_numbers">{hnn}</div>' +
    '<div id="timer_mins" class="timer_numbers">{mnn}</div>' +
    '<div id="timer_seconds" class="timer_numbers">{snn}</div>' +
'<div id="timer_labels">' +
    '<div id="timer_days_label" class="timer_labels">days</div>' +
    '<div id="timer_hours_label" class="timer_labels">hours</div>' +
    '<div id="timer_mins_label" class="timer_labels">mins</div>' +
    '<div id="timer_seconds_label" class="timer_labels">secs</div>' +
'</div>' +
'</div>'
            });
        });
</script>

This is the aspx code

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div class="maindeal">
            <input type="hidden" runat="server" id="HF" />
                <div class="SocialNetworkShare">
                    <asp:Label ID="SocialNetworkShare" runat="server" Text="Share" CssClass="SNS"></asp:Label>
                </div>

Code Behind[I am setting the value for the hidden field in code behind]

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            ShowOfferDetails(System.Configuration.ConfigurationManager.AppSettings.Get("DefaultOffer"), True)          '... here "0;0;0" is given as there is no event argument
        End If
        HF.Value = "10/21/2011"
        MsgBox(HF.Value)
    End Sub

The problem is javascript doesnot detect this value...and throws null exception when i use alert() to check the value.....please help.

1
  • please check the error console and verify is their any error? Commented Oct 20, 2011 at 6:17

2 Answers 2

2

Your HF control is server side and hence its ID in DOM will not be just HF. What you can do is put a class="HF" attribute in the HF control and then from JS you can do $(".HF").val() to get its value

Sign up to request clarification or add additional context in comments.

9 Comments

hey it works but the javascript doesnot calculate the time correct...HF has a value of 2011/10/22 ..but the timer shows 34 mins left..it should show 2 days some hours some mins left.
Please refer to the countdown API doc. The until parameter expects different format that what the HF text value is
How can i change its format to "mm/dd/yyyy"? This is the link to the plugin
var dt = newYear.split('/'); Then until : new Date(parseInt(dt[0]), parseInt(dt[1]) - 1, parseInt(dt[2]))
:) Thanks mate :) You saved a lot of time for me. :)thanks again.
|
1

Try,

 var newYear = document.getElementById('<%=HF.ClientID %>'); //It return Html object
 alert(newYear.value);

 //OR

 var newYear1 = document.getElementById('<%=HF.ClientID %>').value;
 alert(newYear1);

3 Comments

This does not work :( i get objectHTMLInputElement in the msg box.
@SifyJuhy - Use newYear.value or var newYear = document.getElementById('<%=HF.ClientID %>').value;
hey it works but the javascript doesnot calculate the time correct...HF has a value of 2011/10/22 ..but the timer shows 34 mins left..it should show 2 days some hours some mins left.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.