• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1019
  • Last Modified:

Request.Form and Listbox Problems

Hello All

I am creating an Browser based signup for some products a cient sells.

There are a number of 'steps' to the signup process:

1. select required products
2. contact details
3. telephone line details
4. pricing options
5. payment options
6. confirmation

I have decide that for ease it would be best to split these 'steps' into pages, making 6 pages.
I am transferring the information from one page to the next using the Request.form method, and this works great, however, when i transfer the information from page 3 to page 4 i hit a problem:

On page 3 i have two textboxes and two listboxes, the end-user enters a telephone number and a postcode in the textboxes and then clicks add and then details are put in the listboxes. however i have found that on page 4 the only item from the listboxes that has been transferred is the last in each listbox.

Can someone please help???

Also if there is a better way to transferthis amount of info, all i need to do is get all the info to the last page so i can process it

Thanks alot

Hanzs Wolfgang
0
dahquim
Asked:
dahquim
  • 6
  • 6
  • 4
  • +2
1 Solution
 
SlimshaneeyCommented:
Can you disply the pages 3 and 4 here?
0
 
neeraj523Commented:
Helloo

I would prefer if you use Session Varaibles to store info. I am sure the info you are going to store wont be huge and the number of concurent users wont be much.

Using Hidden forms is a good technique to carry forward data to the multiple pages.. but it is tedious to handle.

about your list box problem.. i feel last itme of the list box is selected by default or either all the items in the list box is selected.. that might be the reason u r getting last item on next page..

neeraj523
0
 
SlimshaneeyCommented:
Session variables are a very poor way of saving this data. Passing it via page to page through the form collection is a far better solution. Im sure there is a simple reason for the data not moving from pages 3 to 4. Hopefully we can sort it out.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
SlimshaneeyCommented:
In fact, the only reason I can think of that the last item from each select would be passed is if ALL the select options we marked as Selected (either by error in the logic to auto select a list item), can you view source on the page 3 and see if all the options are marked as seelcted?
0
 
dahquimAuthor Commented:
Slimshaneey: There is no real coding done yet (it is all in html) the asp will be done in the processing of the information on tha last page.

Neeraj: the user does not select an item from the ltsbox, they add items to it. for example if they have 6 telephone numbers then they add ALL 6 to the listbox, then when i set the value of the hidden field on page 4 to the value of the listbox on page 3 only the last item is stored, i need to transfer the whole of the listbox content to the next page.

Thanks for the replys
0
 
neeraj523Commented:
hi Slimshaneey

can you plz explain me why you are figured out that Session varaibles is a very poor wau to save data.. let me add something in my knowladge from you..

seconldy, don't you think what u wrote about the problem of list box is just what i pointed out in my solution ??

apply your own mind to give solution.. there is no meaning to just copy things from here and there..

sorry for hard words.. if u feel bad about it..

neeraj523

0
 
SlimshaneeyCommented:
When submitting the form you will need to select all items in the select. Selects(Listboxes) by default only select the last item in the list.
In your code you will need to run this function for each select to select all items in the listy, they will all get passed to next page then:

<script>
function selAll(selectname) {
for(var i=0;i<selectname.length;i++)
  document.exf1.s1[i].selected=true;
}
</script>
0
 
SlimshaneeyCommented:
Nothing to feel bad about. I simply never use session variables because they can be disabled on some machines. Remeber that session variables are cookie based. A form based variable passing solution will be a more robust solution.
0
 
neeraj523Commented:

hmmm.. i got ur point dahquim

Well.. it is not posisble to transfer whole items of a list to the next page on submit. Alternativally what you can do, add another hidden field to your page and keep on concatinating you phone numbers to this hidden field separated by some identifier, when ever adding a number to ur list box.. On post.. you can retrive this hidden field to get whole data separated by a identfier which can easily sorted into the format u want..

Be carefull about.. if u also allow user to remove item from list box... becasue in that case you also need to update ur hidden field for the removed item..

hope it will work for u..

neeraj523

0
 
dahquimAuthor Commented:
Neeraj: sorry, from what you wrote, it sounded like the user was selecting an item from the listboxes, my appologies
0
 
neeraj523Commented:
Slimshaneey

for your knowladge.. let me tell you that session are not linked to cookies anywhere and user can't disable Session anyhow..

neeraj523
0
 
Lord_McFlyCommented:
I offer the following example - I've only done 4 pages as its an example - but it means you could have all 6 pages in the single page. Using a Prev | Next the page appears to go onto the next  or back to the previos page but in fact its using styles to Hide and Show the current section. As for the <select> when you click to submit the form it creates a list from the <select> stored in the format "sadasd|saasdf|ads|" which you can then split once the form is submit. I included a submit button to show the collection of the form data and to demonstrate the collected <select> stuff.

The page works 'as is' if you wanna give it a try.

<%@ Language=VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<%
Dim sForm(5), sList, iLp

If Request.Form("Action") = "Submit" then
      For iLp = 0 to 5
            sForm(iLp) = Trim(Request.Form("f_"&iLp))
            Response.Write sForm(iLp) & "<br>"
      Next
      
      sList = Split(sForm(5),"|")
      
      For iLp = 0 to UBound(sList)
            Response.Write "From the List: " & sList(iLp) & "<br>"
      Next
      
      Response.End
End If
%>
<html>
<head>
<title>Example</title>
<script language="JavaScript">
<!--
function ShowInfo(TableID)
      {
            var i
            
            for(i=1; i<=4; i++)
                  {
                        if(i==TableID)
                              {
                                    document.getElementById("Info_"+TableID).style.display=""
                              }
                        else
                              {
                                    document.getElementById("Info_"+i).style.display="none"
                              }
                  }
      }
      
function BuildList()
      {
            var i
            var list
            
            list = ""
            
            for(i=0; i<=document.Info.f_3.length - 1; i++)
                  {
                        list = list + document.Info.f_3.options[i].value + "|"
                  }
                  
            
            list = list.substr(0,list.length - 1);
            
            document.Info.f_5.value = list;
            alert(list);
            document.Info.submit()
      }
//-->
</script>
</head>
<body>
<form name="Info" method="post" action="">
      <table width="400" cellspacing="0" cellpadding="0" border="0" ID="Info_1" style="display: ">
            <tr>
                  <td width="300">Info A</td>
                  <td width="100" align="right">
                        <a href="javascript:void(0)" onClick="ShowInfo(2)">Next</a>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                        <table width="400" cellspacing="0" cellpadding="0" border="0">
                              <tr>
                                    <td width="100">Name:</td>
                                    <td width="300">
                                          <input type="text" name="f_0" value="">
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
      </table>
      <table width="400" cellspacing="0" cellpadding="0" border="0" ID="Info_2" style="display: none">
            <tr>
                  <td width="300">Info B</td>
                  <td width="100" align="right">
                        <a href="javascript:void(0)" onClick="ShowInfo(1)">Prev</a> | <a href="javascript:void(0)" onClick="ShowInfo(3)">Next</a>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                        <table width="400" cellspacing="0" cellpadding="0" border="0">
                              <tr>
                                    <td width="100">Age:</td>
                                    <td width="300">
                                          <input type="text" name="f_1" value="">
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
      </table>
      <table width="400" cellspacing="0" cellpadding="0" border="0" ID="Info_3" style="display: none">
            <tr>
                  <td width="300">Info C</td>
                  <td width="100" align="right">
                        <a href="javascript:void(0)" onClick="ShowInfo(2)">Prev</a> | <a href="javascript:void(0)" onClick="ShowInfo(4)">Next</a>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                        <table width="400" cellspacing="0" cellpadding="0" border="0">
                              <tr>
                                    <td width="100">DOB:</td>
                                    <td width="300">
                                          <input type="text" name="f_2" value="">
                                    </td>
                              </tr>
                              <tr>
                                    <td>Stuff:</td>
                                    <td>
                                          <select name="f_3">
                                                <option value="Hello">Hello</option>
                                                <option value="Good bye">Good bye</option>
                                                <option value="See ya">See ya</option>
                                                <option value="Laters">Laters</option>
                                          </select>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
      </table>
      <table width="400" cellspacing="0" cellpadding="0" border="0" ID="Info_4" style="display: none">
            <tr>
                  <td width="300">Info D</td>
                  <td width="100" align="right">
                        <a href="javascript:void(0)" onClick="ShowInfo(3)">Prev</a>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                        <table width="400" cellspacing="0" cellpadding="0" border="0">
                              <tr>
                                    <td width="100">Height:</td>
                                    <td width="300">
                                          <input type="text" name="f_4" value="">
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                        <input type="hidden" name="f_5" value="">
                        <input type="hidden" name="Action" value="Submit">
                        <input type="button" name="Submit" value="Submit" onClick="BuildList()">
                  </td>
            </tr>
      </table>
</form>
</body>
</html>
0
 
dahquimAuthor Commented:
i have been trying to use the ASP script at the start:

Dim sForm(5), sList, iLp

If Request.Form("Action") = "Submit" then
     For iLp = 0 to 5
          sForm(iLp) = Trim(Request.Form("f_"&iLp))
          Response.Write sForm(iLp) & "<br>"
     Next
     
     sList = Split(sForm(5),"|")
     
     For iLp = 0 to UBound(sList)
          Response.Write "From the List: " & sList(iLp) & "<br>"
     Next
     
     Response.End
End If

however it only returns the last item (still), and the list box length can be dynamic.

as for the javascript:

function selAll(selectname) {
for(var i=0;i<selectname.length;i++)
  document.exf1.s1[i].selected=true;
}

It is not pulling ANY results on the next page.

Thanks
0
 
sybeCommented:
@neeraj523
>> let me tell you that session are not linked to cookies anywhere and user can't disable Session anyhow

??? of course Session is related to cookies. If you disable cookies, then the Server is not able to connect the Session variables to the browser. Disabling cookies means disabling Session.

0
 
Lord_McFlyCommented:
The bit at the start only applies if you use the all-in-one page method.

The....

function BuildList()
      {
            var i
            var list
            
            list = ""
            
            for(i=0; i<=document.Info.f_3.length - 1; i++)
                  {
                        list = list + document.Info.f_3.options[i].value + "|"
                  }
                  
            
            list = list.substr(0,list.length - 1);
            
            document.Info.f_5.value = list;
            alert(list);
            document.Info.submit()
      }

..takes all the items in the listbox and stores it in a hidden value - which is collected when the form is submitted.

Your JavaSCript function that you included - doesn't look right - what is it supposed to do?
0
 
SlimshaneeyCommented:
Error in my code for the selection of the items:

function selAll(selectname) {
for(var i=0;i<selectname.length;i++)
  selectname[i].selected=true;
}
0
 
dahquimAuthor Commented:
this was provided by Slimshaneey (see above)
0
 
dahquimAuthor Commented:
Thank you all for your help but i have sorted it.
I have used Lord McFly's code and adapted it for multiple pages. and i now have the whole content of my listbox spearated by commma's

Again Thanks  alot everyone
0
 
Lord_McFlyCommented:
I assume that all-in-one page did not interest you - if you use that method it means you only have to collect the form details once instead of on each page.

On page 3 where they are entering the telephone no. and postcode - do I assume that here they enter more than 1 and hence the need for the listbox?

On this page how do the move onto page 4...button which they click, link which they click.

If this is the case you could use (on page 3) an onClick...

<input type="button" name="Button" value="Click for next section" onClick="BuildList()">

Include in you form the hidden value for the list.

Which you could collect on the next page still using the Request.Form("nameofhiddenvalue")

Hopefully you see what I'm getting at :)
0
 
dahquimAuthor Commented:
Lord Mcfly

i have done it the way that you mention.  building the hidden value on the onclick and then retreiving it on page 4 with the request.form.

Thank you for your help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 6
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now