Can I change the name of an element dynamically?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andersond
    New Member
    • Feb 2007
    • 110

    Can I change the name of an element dynamically?

    I have a form that needs to appear to refresh every 5 lines. Right now I am putting blank tables in the area where the questions will go and swapping them for other tables that actually contain the questions. As you answer one question the next question appears. Because the "next question" in contingent on your answer to the "previous question" I need to be able to give each new question some generic name (like, blank1, blank2, etc) and refresh after each 5 lines. So, if I could change the name of questions once they appear I could move them in or out without leaving spaces.

    For example, if the blank tables are named blank1, blank2, ...blank5 and the tables with questions are named question1, question2, ...question5, when I swap question1 for blank1 I could rename question1 to spacemaintainer 1. Then when it's time to start back on the first line I could swap out question6 (or 7) with spacemaintainer 1, make the next 4 lines not visible and appear to be jumping to the top of a different page.

    Now, how can I rename an object dynamically?
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Ok first off I think what you actually want to do is change the ID attribute, not the name attribute. Chaining a tag's name could potentially change is function. For instance if you had a DIV tag and you changed it's name to "blankX" it could end up no longer functioning as a DIV object.

    Secondly what you are describing sounds unnecessarily complicated. If you just want to make objects appear and disappear you could simply change their "display" attribute to "none" to make them disappear, and then back to "block" to make them re-appear.

    Here is a sample to change an element ID attribute.
    Code:
    <span id="blank1" >Blah Blah Blah</span>
    <script>
        document.getElementById('blank1').id='blank2';
    </script>

    Comment

    Working...