[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-07-23
20
Medium Priority
?
163 Views
Last Modified: 2012-05-05
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...)
0
Comment
Question by:kevp75
  • 11
  • 6
  • 2
  • +1
20 Comments
 
LVL 1

Expert Comment

by:nee_nov
ID: 19553756
hi,

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

Expert Comment

by:bugs021997
ID: 19553800
@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
 
LVL 25

Author Comment

by:kevp75
ID: 19555670
i have mini-me today, I will post code later on
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:bugs021997
ID: 19555692
hahahah sure....

CHEERS...
0
 
LVL 25

Author Comment

by:kevp75
ID: 19566370
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
 
LVL 25

Author Comment

by:kevp75
ID: 19566429
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
 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 2000 total points
ID: 19568577
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
 
LVL 25

Author Comment

by:kevp75
ID: 19570314
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
 
LVL 25

Author Comment

by:kevp75
ID: 19570322
and..one thing I noticed...when you first load the page, there are 1's in every field in this section
0
 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 2000 total points
ID: 19570486
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
 
LVL 25

Author Comment

by:kevp75
ID: 19570778
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
 
LVL 58

Accepted Solution

by:
amit_g earned 2000 total points
ID: 19570793
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
 
LVL 25

Author Comment

by:kevp75
ID: 19570796
doh..missed the initial
arrEmpC = Split(" ", ","), put that in, and it fixed the lbound

but the type mismatch error on 'appEmpC' still shows
0
 
LVL 25

Author Comment

by:kevp75
ID: 19570803
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
 
LVL 58

Expert Comment

by:amit_g
ID: 19570804
What line throws the error?
0
 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 2000 total points
ID: 19570808
<%=appEmpC(IC)%>

should be

<%=arrEmpC(IC)%>

and repeat the same for others.
0
 
LVL 25

Author Comment

by:kevp75
ID: 19570819
doh!
0
 
LVL 25

Author Comment

by:kevp75
ID: 19570826
looks like it did it
0
 
LVL 25

Author Comment

by:kevp75
ID: 19570935
i'll get back to you with points in a bit, I just want to make sure it definately works...
0
 
LVL 58

Expert Comment

by:amit_g
ID: 19570945
No rush. Take your time :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 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