473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Retrieve Droplist data for form

8
I am uncertain of the exact terminology and I am extremely hopeful that some will be able to assist me. 8)

Below is a sample of the code - what I need is to collect the results of the selection.
In this case a user selects a city/cities (in Texas) - This will be added to their favorites list.

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <title>Select Cities</title>
  3. <script language="javascript">
  4. function addOption(selectbox,text,value )
  5. {
  6.     var optn = document.createElement("OPTION");
  7.     optn.text = text;
  8.     optn.value = value;
  9.     selectbox.options.add(optn);
  10. }
  11. function removeOption(listbox,i)
  12. {
  13.     listbox.remove(i);
  14. }
  15. function addOption_list(){
  16.  for(i=document.drop_list.Category.options.length-1;i>=0;i--)    {
  17.   var Category=document.drop_list.Category;
  18.   if(document.drop_list.Category[i].selected){
  19.     addOption(document.drop_list.SubCat, document.drop_list.Category[i].text, document.drop_list.Category[i].value);
  20.     removeOption(Category,i);
  21.     }
  22.   }
  23. }
  24. function remOption(listbox,text,value )
  25. {
  26.     var optn = document.createElement("OPTION");
  27.     optn.text = text;
  28.     optn.value = value;
  29.     listbox.options.add(optn);
  30. }
  31.  
  32. function remove2Option(selectbox,i)
  33. {
  34.     selectbox.remove(i);
  35. }
  36. function remOption_list(){
  37.  for(i=document.drop_list.SubCat.options.length-1;i>=0;i--)    {
  38.   var SubCat=document.drop_list.SubCat;
  39.   if(document.drop_list.SubCat[i].selected){
  40.     remOption(document.drop_list.Category, document.drop_list.SubCat[i].text, document.drop_list.SubCat[i].value);
  41.     remove2Option(SubCat,i);
  42.     }
  43.   }
  44. }
  45. </script>
  46. </head>
  47. <body>
  48. <form name="drop_list" action="results.php" method="post">
  49. <table width="200" cellspacing="0" cellpadding="5" border="0">
  50.  <tr>  
  51.   <td valign="top" width="90">
  52.   <select name="Category" multiple="multiple" size="10">
  53.    <option value="Amarillo">Amarillo</option>
  54.    <option value="Austin">Austin</option>
  55.    <option value="Dallas">Dallas</option>
  56.    <option value="Galveston">Galveston</option>
  57.    <option value="Houston">Houston</option>
  58.    <option value="Irving">Irving</option>
  59.    <option value="Killeen">Killeen</option>
  60.    <option value="Laredo">Laredo</option>
  61.    <option value="Lubbock">Lubbock</option>
  62.    <option value="Plano">Plano</option>
  63.    <option value="San Antonio">San Antonio</option>
  64.    <option value="Waco">Waco</option>
  65.   </select>
  66.   </td><td valign="middle" width="20">
  67.   <input onclick="addOption_list()" ;="" value="ADD &raquo;" type="button"><br />
  68.   <input onclick="remOption_list()" ;="" value="&laquo; REMOVE" type="button"></td>
  69.   <td valign="top" width="90">
  70.   <select name="SubCat" multiple="multiple" size="10">
  71.   </select></td>
  72.  </tr>
  73. </table><br />
  74. <input type="submit" value="Select">
  75. </form>
  76. </body>


The results are supposed to be sent to another page - However, they are not able to be retrieved??
results.php => should show the information, correct?

Expand|Select|Wrap|Line Numbers
  1. <table cellspacing="2" cellpadding="0" width="100%" border="0">
  2.  <tr>
  3.   <td><? echo $SubCat; ?></td>
  4.  </tr>
  5. </table>
The information will eventually be inserted into a database. I am just trying to determine how I gather the users selection?

Thank in advance...
Mar 5 '09 #1
9 1794
Dormilich
8,658 Expert Mod 8TB
@phillx
I think it's due to the fact, that the second select box has no option selected to be submitted by the form (it's no use to submit an unselected option, is it?).
Mar 5 '09 #2
phillx
8
I agree - how do I go about making certain that this is accomplished?

I am able to have the items selected and moved to the other listbox...
Mar 5 '09 #3
Dormilich
8,658 Expert Mod 8TB
after you move the user's selection, you have to select them again in the second box (you may do that just before sending).
Mar 6 '09 #4
phillx
8
Dormilich -

Thank you for the reply.

I completely understand that - the problem or confussion that I am having is how do I go about reselecting the transferred data?

Can you provide me with a possible solution?

Thanx
Mar 6 '09 #5
Dormilich
8,658 Expert Mod 8TB
basic idea (untested):
Expand|Select|Wrap|Line Numbers
  1. function addOption(selectbox,text,value )
  2. {
  3.     var optn = document.createElement("option");
  4.     optn.text = text;
  5.     optn.value = value;
  6.     optn.selected = "selected";
  7.     selectbox.options.add(optn);
  8. }
Mar 6 '09 #6
phillx
8
Dormilich -

Awesome!

However, I just tested the above and it only partially works. :-(

This will highlight (select) each item.

Although, only the last submission to be transferred into the second listbox is actually selected (sent on to the following page) ??

hmmm - any suggestions on how to select all items? I know it has been done on other sites - I am just not certain how to go about accomplishing it?

I really appreciate your (and anyone elses) assistance!
Mar 6 '09 #7
acoder
16,027 Expert Mod 8TB
The correct add method has two arguments, but IE uses one, so for cross-browser support, try this:
Expand|Select|Wrap|Line Numbers
  1.     optn.selected = true;
  2.     try {
  3.       selectbox.options.add(optn,null);
  4.     } catch {
  5.       selectbox.options.add(optn);
  6.     }
  7.  
In your PHP code, are you setting the $subCat variable properly to get the posted values?
Mar 7 '09 #8
phillx
8
Acoder -
Unfortunately - that Code produced several javascript errors?!

Yes, I do have the the code getting the $subCat otherwise I would have no results? I am a bit confused by that. Is there another way of retrieving data?
Mar 8 '09 #9
acoder
16,027 Expert Mod 8TB
Are you sure you replaced the code in addOption()?

You can change the name of the options to subCat[] to use it as an array in PHP.
Mar 9 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stanley J Mroczek | last post by:
I am trying to load a droplist in VB when the edit is clicked in a datagrid. I tried to use OnDataBinding and loading the droplist in subroutine "loaddd". I get this error Object reference not set...
4
by: TJS | last post by:
After a post back the selected index should be rest in a droplist to match user's choice, but page always show selected item as first one in the droplist. How can iforce the selected item to be...
2
by: TJS | last post by:
need help with trying to set selected value on a droplist. -- tried vCaptainID as integer and string , no luck -- tried it in pre render and also after droplist is created , no luck =========...
5
by: TJS | last post by:
I need to add validation to drodownlist control but it sends back an error message that says: "System.Web.UI.WebControls.DropDownList' does not allow child controls" the code is : If...
2
by: TJS | last post by:
I have a control, called FieldBuilder, which generates a droplist dynamically for a form. I want to add validation to the droplist thru the 'OnItemCreated' function. i can't seem to get the...
0
by: yuchang | last post by:
Hi, I try to use a droplist control to show a list value from Database table "A", and the droplist control is an item of a formview control, its data from Database table "B". My problem is how...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
21
by: giandeo | last post by:
Hello Experts. Is it possible to retrieve the value from a populated pull down menu from a database and then use that value to access the same database to get the related fields. Example: ...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.