How to get part of a form values to stay...

I have a job application form built.  Part of it, allows you to click a link to display more sections for 'Previous Employment'.

My issue is, because the javascript that controls that link (section) clones the entire section I am finding that I cannot simply put value="<%=theField%>" as there may be more than one section.

What can I do?  I need to keep the functionality as it is...  (here's a link... http://www.lightbridgehospice.org/Careers/App.asp  if you click the 'Add Another Employer' you will see what I mean by clone...)
LVL 25
kevp75Asked:
Who is Participating?
 
amit_gCommented:
Did you modify the else block to have arrEmpC = Split(" ", ",") for each form element? Also the first argument of Split is a string with single blank char (not empty string).

                  If (request.form("appEmpC") <> "") then
                        arrEmpC = Split(request.form("appEmpC"), ",")
                  else
                        arrEmpC = Split(" ", ",")
                  end if
0
 
nee_novCommented:
hi,

Can you tell where and why you need to assign the value  -- (Value="<%=theField%>" ) ? And where do these value come from?
0
 
bugs021997Commented:
@kevp75

Can you bit more clear as to what you are looking for....


If you are looking for cloning the element values as per the last textbox....? then get the value of the Textbox(arrayIndex) for the last textbox and then replicate its value further.

Hope this is what you are looking at....i would be able to look into the problem in more descriptive manner when you have the issue put forth

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
kevp75Author Commented:
i have mini-me today, I will post code later on
0
 
bugs021997Commented:
hahahah sure....

CHEERS...
0
 
kevp75Author Commented:
sorry for the wait folks....here's my code:

function delRow(oThis)
{
      var index = oThis.parentNode.parentNode.rowIndex;
      var table = document.getElementById('empTbl');
      var tr;
      var i;
      for (i = 0 ; i < 7 ; i++)
      {
            table.deleteRow(index - i);
      }
}
function addRow()
{
      var table = document.getElementById('empTbl');
      var tbody = table.getElementsByTagName('tbody')[0];
      var tr;
      var i;
      for (i = 0 ; i < 7 ; i++)
      {
            tr = table.insertRow(table.rows.length);
            cloneCells(table.rows[i], tr);
      }
}
function cloneCells(oSourceTR, oDestinaionTR)
{
      var oDestinaionCell;
      var inputs;
      var i;
      var j;
      for (i = 0 ; i < oSourceTR.cells.length ; i++)
      {
            oDestinaionCell = oDestinaionTR.insertCell(oDestinaionTR.cells.length);
            oDestinaionCell.innerHTML = oSourceTR.cells[i].innerHTML;
            inputs = oDestinaionCell.getElementsByTagName("input");
            for (j = 0 ; j < inputs.length ; j++)
            {
                  inputs[j].value = "";
            }
      }
}


<!--Rest of page and form-->
            <tr>
                  <td><div align="right"><a href='#' onclick="addRow();return false;">Add Another Employer</a></div>
            <table width="100%" border="0" cellspacing="0" cellpadding="2" id="empTbl" style="border:1px solid #000;">
            <tbody>
                              <tr>
                                    <td>Company Name: <input name="appEmpC" type="text" class="textbox" id="appEmpC" value="" size="77" />
                                    Telephone: <input name="appEmpPhone" type="text" class="textbox" id="appEmpPhone" value="" size="23" /></td>
                              </tr>
                              <tr>
                                    <td>Address: <input name="appEmpAdd" type="text" class="textbox" id="appEmpAdd" value="" size="75" />
                                    Dates Of Employment: <input name="appEmpDF" type="text" class="textbox" id="appEmpDF" value="" size="7" /> to <input name="appEmpDT" type="text" class="textbox" id="appEmpDT" value="" size="7" /></td>
                              </tr>
                              <tr>
                                    <td>Supervisor's Name:
                                          <input name="appEmpSup" type="text" class="textbox" id="appEmpSup" value="" size="80" />
                                          Pay $
                                          <input name="appEmpPay" type="text" class="textbox" id="appEmpPay" value="" size="7" />
                                          per
                                          <input name="appEmpRate" type="text" class="textbox" id="appEmpRate" value="" size="7" /></td>
                              </tr>
                              <tr>
                                    <td>Job Title/Duties: <input name="appEmpDuties" type="text" class="textbox" id="appEmpDuties" value="" size="117" /></td>
                              </tr>
                              <tr>
                                    <td>Reason For Leaving
                                          <input name="appEmpLeft" type="text" class="textbox" id="appEmpLeft" value="" size="113" /></td>
                              </tr>
                              <tr style="display:none">
                                  <td><a style="padding:5px 0 5px 715px;" href='#' onclick="delRow(this);return false;">Remove Employer</a></td>
                            </tr>
                              <tr>
                                  <td><hr /></td>
                            </tr>
            </tbody>
            </table>                  </td>
            </tr>
0
 
kevp75Author Commented:
when I request the field values the come through as a comma-dlimited list, so I split on that, do an if isarray check (if valid, then display in the email that gets sent), but what I have is validation checks on certain fields above this area, and if one fails, I need to be able to keep the values the user typed in, into the fields.  However when a potential applicant hits submit, and a validation fails, this section goes back to being only one section (meaning if they had 'Added' another prev. employer....the one they added disappears)

I know I need to put in value="<%=request.form("appEmpXXXX")%>, however it is pointless, since:

A)  It's a comma-delimited list
b)  The extra section(s) disappear anyways...
0
 
amit_gCommented:
Since you are doing a postback, what is done by javascript would be lost. You will have to recreate it back again using in asp server side code. You need to check if request.form("appEmpXXXX") has comma in it, if yes then you need to split it and count how many emplyement sections you need to make. Then make anything inside of TBODY tag n number of times. I would do something like this ...

If (request.form("appEmpC") <> "") then
    arrEmpC = Split(request.form("appEmpC"), ",")
    EmployerCount = UBound(arrEmpC) - LBound(arrEmpC) + 1
else
    EmployerCount = 1
end if

later in HTML...

<!--Rest of page and form-->
            <tr>
                  <td><div align="right"><a href='#' onclick="addRow();return false;">Add Another Employer</a></div>
            <table width="100%" border="0" cellspacing="0" cellpadding="2" id="empTbl" style="border:1px solid #000;">
            <tbody>
<%
    FOR I = 1 to EmployerCount
%>
                              <tr>
                                    <td>Company Name: <input name="appEmpC" type="text" class="textbox" id="appEmpC" value="" size="77" />
                                    Telephone: <input name="appEmpPhone" type="text" class="textbox" id="appEmpPhone" value="" size="23" /></td>
                              </tr>
...
...
Rest of TR
...
...
                              <tr>
                                  <td><hr /></td>
                            </tr>
<%
    Next
%>

            </tbody>
            </table>                  </td>
            </tr>
0
 
kevp75Author Commented:
hey amit!

tried what you suggested...and, well, it semi-worked.

The values get populated, however what is being displayed is the comma-delimited list.

here's what I have now for this section:
                  <%
                  If (request.form("appEmpC") <> "") then
                        arrEmpC = Split(request.form("appEmpC"), ",")
                        EmployerCount = UBound(arrEmpC) - LBound(arrEmpC) + 1
                  else
                        EmployerCount = 1
                  end if
                  %>
            <tbody>
                  <%
                        FOR IC = 1 to EmployerCount
                  %>

                              <tr>
                                    <td>Company Name: <input name="appEmpC" type="text" class="textbox" id="appEmpC" value="<%=appEmpC&IC%>" size="77" />
                                    Telephone: <input name="appEmpPhone" type="text" class="textbox" id="appEmpPhone" value="<%=appEmpPhone&IC%>" size="23" /></td>
                              </tr>
                              <tr>
                                    <td>Address: <input name="appEmpAdd" type="text" class="textbox" id="appEmpAdd" value="<%=appEmpAdd&IC%>" size="75" />
                                    Dates Of Employment: <input name="appEmpDF" type="text" class="textbox" id="appEmpDF" value="<%=appEmpDF&IC%>" size="7" /> to <input name="appEmpDT" type="text" class="textbox" id="appEmpDT" value="<%=appEmpDT&IC%>" size="7" /></td>
                              </tr>
                              <tr>
                                    <td>Supervisor's Name:
                                          <input name="appEmpSup" type="text" class="textbox" id="appEmpSup" value="<%=appEmpSup&IC%>" size="80" />
                                          Pay $
                                          <input name="appEmpPay" type="text" class="textbox" id="appEmpPay" value="<%=appEmpPay&IC%>" size="7" />
                                          per
                                          <input name="appEmpRate" type="text" class="textbox" id="appEmpRate" value="<%=appEmpRate&IC%>" size="7" /></td>
                              </tr>
                              <tr>
                                    <td>Job Title/Duties: <input name="appEmpDuties" type="text" class="textbox" id="appEmpDuties" value="<%=appEmpDuties&IC%>" size="117" /></td>
                              </tr>
                              <tr>
                                    <td>Reason For Leaving
                                          <input name="appEmpLeft" type="text" class="textbox" id="appEmpLeft" value="<%=appEmpLeft&IC%>" size="113" /></td>
                              </tr>
                              <tr style="display:none">
                                  <td><a style="padding:5px 0 5px 715px;" href='#' onclick="delRow(this);return false;">Remove Employer</a></td>
                            </tr>
                              <tr>
                                  <td><hr /></td>
                            </tr>
                              <%next%>
            </tbody>
0
 
kevp75Author Commented:
and..one thing I noticed...when you first load the page, there are 1's in every field in this section
0
 
amit_gCommented:
Do this for form fields within the table.

<%
                  If (request.form("appEmpC") <> "") then
                        arrEmpC = Split(request.form("appEmpC"), ",")
                  else
                        arrEmpC = Split(" ", ",")
                  end if

                  If (request.form("appEmpPhone") <> "") then
                        arrEmpPhone = Split(request.form("appEmpPhone"), ",")
                  else
                        arrEmpPhone = Split(" ", ",")
                  end if
%>

                  <%
                        FOR IC = LBound(arrEmpC) to UBound(arrEmpC)
                  %>
                              <tr>
                                    <td>Company Name: <input name="appEmpC" type="text" class="textbox" id="appEmpC" value="<%=Trim(arrEmpC(IC))%>" size="77" />
                                    Telephone: <input name="appEmpPhone" type="text" class="textbox" id="appEmpPhone" value="<%=Trim(arrEmpPhone(IC))%>" size="23" /></td>
                              </tr>

Note that the initialization of value attribute is <%=Trim(arrEmpC(IC))%> i.e. from the array of values. So the idea is to convert all form elements (in the table) values  to array and then use that array to initialize those.
0
 
kevp75Author Commented:
ok...using:
                  <%
                        FOR IC = LBound(arrEmpC) to UBound(arrEmpC)
                  %>

on initial page load throughs out the error on lbound, and I only get a Type mismatch: 'appEmpC'
0
 
kevp75Author Commented:
doh..missed the initial
arrEmpC = Split(" ", ","), put that in, and it fixed the lbound

but the type mismatch error on 'appEmpC' still shows
0
 
kevp75Author Commented:
here's my full code now:
            <table width="100%" border="0" cellspacing="0" cellpadding="2" id="empTbl" style="border:1px solid #000;">
                  <%
                  If (request.form("appEmpC") <> "") then
                        arrEmpC = Split(request.form("appEmpC"), ",")
                  else
                        arrEmpC = Split(" ", ",")
                  end if
                  If (request.form("appEmpPhone") <> "") then
                        arrEmpPhone = Split(request.form("appEmpPhone"), ",")
                  else
                        arrEmpPhone = Split(" ", ",")
                  end if
                  If (request.form("appEmpAdd") <> "") then
                        arrEmpAdd = Split(request.form("appEmpAdd"), ",")
                  else
                        arrEmpAdd = Split(" ", ",")
                  end if
                  If (request.form("appEmpDF") <> "") then
                        arrEmpDF = Split(request.form("appEmpDF"), ",")
                  else
                        arrEmpDF = Split(" ", ",")
                  end if
                  If (request.form("appEmpDT") <> "") then
                        arrEmpDT = Split(request.form("appEmpDT"), ",")
                  else
                        arrEmpDT = Split(" ", ",")
                  end if
                  If (request.form("appEmpSup") <> "") then
                        arrEmpSup = Split(request.form("appEmpSup"), ",")
                  else
                        arrEmpSup = Split(" ", ",")
                  end if
                  If (request.form("appEmpPay") <> "") then
                        arrEmpPay = Split(request.form("appEmpPay"), ",")
                  else
                        arrEmpPay = Split(" ", ",")
                  end if
                  If (request.form("appEmpRate") <> "") then
                        arrEmpRate = Split(request.form("appEmpRate"), ",")
                  else
                        arrEmpRate = Split(" ", ",")
                  end if
                  If (request.form("appEmpDuties") <> "") then
                        arrEmpDuties = Split(request.form("appEmpDuties"), ",")
                  else
                        arrEmpDuties = Split(" ", ",")
                  end if
                  If (request.form("appEmpLeft") <> "") then
                        arrEmpLeft = Split(request.form("appEmpLeft"), ",")
                  else
                        arrEmpLeft = Split(" ", ",")
                  end if

                  %>
            <tbody>
                  <%
                        FOR IC = LBound(arrEmpC) to UBound(arrEmpC)

                  %>

                              <tr>
                                    <td>Company Name: <input name="appEmpC" type="text" class="textbox" id="appEmpC" value="<%=appEmpC(IC)%>" size="77" />
                                    Telephone: <input name="appEmpPhone" type="text" class="textbox" id="appEmpPhone" value="<%=appEmpPhone(IC)%>" size="23" /></td>
                              </tr>
                              <tr>
                                    <td>Address: <input name="appEmpAdd" type="text" class="textbox" id="appEmpAdd" value="<%=appEmpAdd(IC)%>" size="75" />
                                    Dates Of Employment: <input name="appEmpDF" type="text" class="textbox" id="appEmpDF" value="<%=appEmpDF(IC)%>" size="7" /> to <input name="appEmpDT" type="text" class="textbox" id="appEmpDT" value="<%=appEmpDT(IC)%>" size="7" /></td>
                              </tr>
                              <tr>
                                    <td>Supervisor's Name:
                                          <input name="appEmpSup" type="text" class="textbox" id="appEmpSup" value="<%=appEmpSup(IC)%>" size="80" />
                                          Pay $
                                          <input name="appEmpPay" type="text" class="textbox" id="appEmpPay" value="<%=appEmpPay(IC)%>" size="7" />
                                          per
                                          <input name="appEmpRate" type="text" class="textbox" id="appEmpRate" value="<%=appEmpRate(IC)%>" size="7" /></td>
                              </tr>
                              <tr>
                                    <td>Job Title/Duties: <input name="appEmpDuties" type="text" class="textbox" id="appEmpDuties" value="<%=appEmpDuties(IC)%>" size="117" /></td>
                              </tr>
                              <tr>
                                    <td>Reason For Leaving
                                          <input name="appEmpLeft" type="text" class="textbox" id="appEmpLeft" value="<%=appEmpLeft(IC)%>" size="113" /></td>
                              </tr>
                              <tr style="display:none">
                                  <td><a style="padding:5px 0 5px 715px;" href='#' onclick="delRow(this);return false;">Remove Employer</a></td>
                            </tr>
                              <tr>
                                  <td><hr /></td>
                            </tr>
                              <%next%>
            </tbody>
            </table>
0
 
amit_gCommented:
What line throws the error?
0
 
amit_gCommented:
<%=appEmpC(IC)%>

should be

<%=arrEmpC(IC)%>

and repeat the same for others.
0
 
kevp75Author Commented:
doh!
0
 
kevp75Author Commented:
looks like it did it
0
 
kevp75Author Commented:
i'll get back to you with points in a bit, I just want to make sure it definately works...
0
 
amit_gCommented:
No rush. Take your time :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.