session variables within expandable/collapseable sections

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 ="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");
      = "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">

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joseph MelnickSenior Software Developer - Pharmacy ApplicationsCommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.