We help IT Professionals succeed at work.

session variables within expandable/collapseable sections

JasonDell asked
Medium Priority
Last Modified: 2011-09-20
Hi guys,

I have some code (shown below) that allows a user to add as many products as they wish (if available - $product_available) by selecting the checkbox at the bottom of each section. I would like to use this for collecting data from the user. Looking at the post variables that are sent to test5a.php, I have a seperate variable and its associated value for each field - great! I am thinking of storing these values into session variables... but I am not sure how to use a similar loop as with the creation of the fields for re-display / confirmation purposes of the data collected from the user so that they can make any changes to the data if necessary?

Thank you for your help with this. Please get back to me if something is not clear.

<script type="text/javascript">

var cnt = 0;
var field = 4;

var TABLE_START = "<table width='367' border='0' cellspacing='0' cellpadding='0'>";
var TABLE_END = "</table>";
var TR_START = "<tr>";
var TR_END = "</tr>";
var INFO_TD = "<td class='main'>&nbsp;&nbsp;";
var INPUT_TD = "<td class='main'><input type='text'";
var CHECKBOX_FLD_START = "<input id='createCheck";
var CHECKBOX_FLD_END = "' type='checkbox' value='' onclick='createFields(this);'>";
var DIV_START_ID_START = "<div id='appendDiv";
var DIV_START_ID_END = "'>";
var DIV_END = "</div>";

function init(){
    // document.account_edit.doc_copy.onclick();
} // end function init

function onDocSelect(frm, tp) {
      frm.className = frm.className.replace(/Doc_[a-z]+/i,''); //clear ordertype from classname
      frm.className += ' Doc_' + tp; //set net doctype

function createFields(elem)
     var ar = new Array();
     var cur = elem.id.split("createCheck")[1];
     var temp = parseInt(cur) + 1;
     var appendDivElem = document.getElementById("appendDiv" + cur);
     var test = document.getElementById("appendDiv" + temp);
     if (elem.checked && cur <= cnt && (test == null || test == "undefined"))

               for (i = 1; i < 5; i++)
                    ar.push("Info " + i + ":</td>");
                    ar.push(" name='info_" + field + "' id='info_" + field + "'></td>");


               var newDiv = document.createElement("DIV");
               newDiv.id = "appendDiv" + cnt;
               newDiv.innerHTML = ar.join("");

          cnt = cur;

.onDoc {display:none;}
form.Doc_on                        .onDoc               {display:block;}
form.Doc_off                        .onDoc               {display:none;}

<body onLoad="init()">
<FORM action="test5a.php" method="post">

     <table width="398" border="0" cellpadding="0" cellspacing="0">

             <?php // remove query
             $product_available = 1;
             <td class="main"><img src="/images/1ptrans.gif" width="1" height="2"><br>&nbsp;
          <?php if ($_SESSION['doc_copy'] == '1') { ?>
                                    <input type="checkbox" name="doc_copy" value="1" checked="checked"
                                onclick="onDocSelect(this.form, this.checked ? 'on' : 'off');"/>
                    <?php } else { ?>
                <?php if ($product_available == 1) { ?>
                                    <input type="checkbox" name="doc_copy" value="1"
                                onclick="onDocSelect(this.form, this.checked ? 'on' : 'off');"/>
                          <?php } else { ?>
                                    <input type="checkbox" name="doc_copy" value="1" disabled />
                          <?php } ?>
                    <?php } ?>
                    <b>Product X</b>                                        </td>
          <td class="main">
               <div class="onDoc" align="center">
               <div id="appendDiv0">
               <table width="367" border="0" cellspacing="0" cellpadding="0">
                    <td class="main">&nbsp;&nbsp;Info 1:</td>
                    <td class="main"><input type="text" name="info_1" id="info_1"></td>
                    <td class="main">&nbsp;&nbsp;Info 2:</td>
                    <td class="main"><input type="text" name="info_2" id="info_2"></td>
                    <td class="main">&nbsp;&nbsp;Info 3:</td>
                    <td class="main"><input type="text" name="info_3" id="info_3"></td>
                    <td class="main">&nbsp;&nbsp;Info 4:</td>
                    <td class="main"><input type="text" name="info_4" id="info_4" ></td>
             <input id="createCheck0" type="checkbox" value="" onclick="createFields(this);">
<input name="" type="submit" value="submit">

Watch Question

Senior Software Developer - Pharmacy Applications

Your javascript could be simplified to build a new input and place it into the dom inside your form to represent values clicked.
It could be as simple as a string

the script that your are posting to could intercept and break it up into something meaningful when processing the $_POST array.

Joseph Melnick

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.