Search code examples
javascriptcsstabbed

same fields within tabbed content


I have a form that covers CSS tabbed content and will calculate stuff based on selected fields from tabs.

Question 1: Will the form work in general across multiple tabs?

Question 2: I have fields that will repeat in multiple tabs. How do I managed this? Just copy and paste them or use different IDs? Not sure how form will behave in this case. Please advise.

<html>
  <head>
    <script type="text/javascript">

      function activateTab(pageId) {
          var tabCtrl = document.getElementById('tabCtrl');
          var pageToActivate = document.getElementById(pageId);
          for (var i = 0; i < tabCtrl.childNodes.length; i++) {
              var node = tabCtrl.childNodes[i];
              if (node.nodeType == 1) { /* Element */
                  node.style.display = (node == pageToActivate) ? 'block' : 'none';
              }
          }
      }

    </script>
  </head>
  <body>
    <ul>
      <li>
        <a href="javascript:activateTab('page1')">Tab 1</a>
      </li>
      <li>
        <a href="javascript:activateTab('page2')">Tab 2</a>
      </li>
    </ul>
    <div id="tabCtrl">

<form name="myForm" METHOD=post ACTION="/Calculate">

     <div id="page1" style="display: block;">Page 1
        <select name="field1" id="field1">
        <option value="0" selected="selected">- Select</option>
        <option value="65">Value 1</option>
        <option value="75">Value 2</option>
        </select>
      </div>

      <div id="page2" style="display: none;">Page 2
        <select name="field1" id="field1">
            <option value="0" selected="selected">- Select</option>
            <option value="65">Value 1</option>
            <option value="75">Value 1</option>
        </select>
        <select name="field2" id="field2">
            <option value="0" selected="selected">- Select</option>
            <option value="1">Value 1</option>
            <option value="2">Value 2</option>
        </select>
      </div>      
     </form>      
    </div>
  </body>
</html>

Solution

  • As Austin suggested two forms are the answers for my problem