session variables within expandable/collapseable sections

Posted on 2006-03-30
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 ="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">

Question by:JasonDell
    1 Comment
    LVL 11

    Accepted Solution


    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now