Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:05:50+00:00 2026-06-13T04:05:50+00:00

I am having a problem setting/getting a hidden input’s value with JavaScript, and can’t

  • 0

I am having a problem setting/getting a hidden input’s value with JavaScript, and can’t see what I’m doing wrong.

What I am basically trying to do is maintain the state of expandable/collapsable divs on my page across form submissions. So I put a hidden input on the page to hold the state of the divs. When a div is expanded/collapsed, I change the value of the input. When the page loads, I read the value of the input and set the state of the divs.

But the value of the input is getting lost. I verify through alerts that it is being set correctly, and then when I read it on load, I verify with an alert that it is empty. Here is the pertinent code:

<input type="hidden" name="ECState" id="hdnECState" />

<script language="javascript" type="text/javascript">
<!--
    var ecValue;

    function ec(div, btn) {
        //expands or collapses an error detail div
        var e = document.getElementById(div);
        var b = document.getElementById(btn);
        var ecStr = div.toString() + ',' + btn.toString() + '|'
        if (e.style.display == 'block') {
            e.style.display = 'none';
            b.src = '../../Images/plus.gif';
            ecValue = ecValue.replace(ecStr, '');
        }
        else {
            e.style.display = 'block';
            b.src = '../../Images/minus.gif';
            ecValue = ecValue + ecStr;
        }
        alert(ecValue);
        document.getElementById('hdnECState').value = ecValue;
    }
    function reexpand() {
        //restores the expanded state of the error detail divs
        var pipe, comma, db, div, btn, e, b;
        var n = document.getElementById('hdnECState').value;
        alert('n=' + n);
        if (n != '') {
            pipe = n.indexOf('|');
            while (pipe > 0) {
                db = n.substring(0, pipe);
                comma = db.indexOf(',');
                if (comma > 0) {
                    div = db.substring(0, comma);
                    btn = db.substring(comma + 1);
                    e = document.getElementById(div);
                    b = document.getElementById(btn);
                    e.style.display = 'block';
                    b.src = '../../Images/minus.gif';
                }
                n = n.substring(pipe+1);
                pipe = n.indexOf('|');
            }
        }
    }

    reexpand();

//-->
</script>

When I expand a div, I see the alert from ec() showing that ecValue is ‘foo,bar|’.

But after submitting the form, I see the alert from reexpand() saying ‘n=’.

Anybody see what I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:05:51+00:00Added an answer on June 13, 2026 at 4:05 am

    Rudu supplied the answer in a comment, but since I can’t mark a comment as the answer, here it is:

    I was forgetting that hidden inputs don’t automatically keep their value in ViewState across form submissions. I needed to re-value the hidden input on the back end in page load and then everything worked fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem setting a cookie and doing a 302 redirect In chrome
I am having a problem setting the background of UITableView to a UIImageView (see
I am having a problem with setting cookie with php. I am trying to
I am having problem with the XCode->Project->Edit Active Target projectname setting I am trying
Am having a problem setting the gradient background of the selected listviewitem. Everytime I
I am having a problem setting up a simple test project for SignalR. I
I am having a problem setting up the following in Visual Studio 2008: a
I am having a problem when setting VB.NET list object to another. In the
hi forum member I am having one problem with setting the radiofield in the
I am having a problem where a cookie I am setting is being lost

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.