Solved

Request.Form and Listbox Problems

Posted on 2004-04-27
20
1,006 Views
Last Modified: 2012-05-04
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
Comment
Question by:dahquim
  • 6
  • 6
  • 4
  • +2
20 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10926847
Can you disply the pages 3 and 4 here?
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 10926864
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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10926877
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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10926886
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
 

Author Comment

by:dahquim
ID: 10926910
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
 
LVL 22

Expert Comment

by:neeraj523
ID: 10926940
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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10926944
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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10926951
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
 
LVL 22

Expert Comment

by:neeraj523
ID: 10926958

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
 

Author Comment

by:dahquim
ID: 10926959
Neeraj: sorry, from what you wrote, it sounded like the user was selecting an item from the listboxes, my appologies
0
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.

 
LVL 22

Expert Comment

by:neeraj523
ID: 10926972
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
 
LVL 6

Accepted Solution

by:
Lord_McFly earned 125 total points
ID: 10927044
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
 

Author Comment

by:dahquim
ID: 10927311
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
 
LVL 28

Expert Comment

by:sybe
ID: 10927316
@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
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10927335
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
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10927363
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
 

Author Comment

by:dahquim
ID: 10927575
this was provided by Slimshaneey (see above)
0
 

Author Comment

by:dahquim
ID: 10927709
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
 
LVL 6

Expert Comment

by:Lord_McFly
ID: 10927717
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
 

Author Comment

by:dahquim
ID: 10927768
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

20 Experts available now in Live!

Get 1:1 Help Now