Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 15th, 2006, 03:54 PM
Registered User
 
Join Date: Sep 2006
Location: Northfield, NH, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to retain form values from dependent list ?

Hello p2p,

I have a html page (ad_form_online.html) with 2 selection lists. There is a parent list (Category) and the other one (Subcategory) is dependent on this parent. The second list is populated depending on the parent list selection.

My Problem: I want to retain the values on the 2 selection lists after submit. I am able to retain the first list values and the second list's select element, but not second list's array (It defaults to the first of five arrays).

How can I retain the 2nd selection list array values after submitting a form? Any suggestions would be really helpful...

Thank you in advance,
George

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~

The JavaScript code:

<script language="javascript" type="text/javascript">
<!-- Begin category select
// declare arrays
var Business = new Array("Bus. Cards","Employment","Services", "", "", "", "", "");
var Household = new Array("Antiques", "Appliances", "Collectibles", "Electronics",
"Furniture", "Musical Instr.", "Other HH", "Sporting Goods");
var Miscellaneous = new Array("Baby / Kids", "Jewelry", "Office Equipment", "Other Misc.",
"Pets / Animals", "Tools", "Wanted", "Yard Equipment");
var Real_Estate = new Array("Home / Commercial", "Land / Acreage", "Rentals", "Vacation", "", "", "", "");
var Vehicles = new Array("Antique / Classic", "Autos / MiniVans", "Cycle / OHRVs", "Parts /
Accy", "RVs / Trailers", "Trucks / Vans / SUVs", "Watercraft / Accy", "");


function swapOptions(the_array_name)
//ex. If you selected "Business," the_array_name will equal the string "Business"
{
  var numbers_select = window.document.FrontPage_Form1.O2_Subcategory;
//Sets a variable to refer to the second list, the Subcategory.

  var the_array = eval(the_array_name);
//The result of this line is that the variable the_array will equal one of the arrays //defined above. If the_array_name is Business, the_array will equal the Business array.

  setOptionText(window.document.FrontPage_Form1.O2_S ubcategory, the_array);
//Does the work of setting the values of the list select to the contents of the_array.
}


function setOptionText(the_select, the_array)
var deel1 = 0
{
  for (loop=0; loop < the_select.options.length; loop++)
  {
    the_select.options[loop].text = the_array[loop];
  }
}
//The options property of a select element is an array of all that select's options. Because //it's an array, you can find out how many options are in a select using the length property //of arrays.

//The first time you hit the loop, the loop variable equals 0. If you selected "Household", //the_array[0] will be "Antiques", so this line will change the first option in the list //select to "Antiques". The next time through the loop, loop[1] second option in the list //select will equal "Appliances", etc.

//End category select-->
</script>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~

My form code:

form enctype="multipart/form-data" method="POST" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">

<table width="640" bgcolor="#dedede" align="center" valign="middle" cellpadding="8"

cellspacing="0" border="1" bordercolor="#111111">

<tr>
<td align="right"><b>Category & Subcategory </b>*
 :
<br />
(select a category and a subcategory) </td>

<td align="center">
  <table width="94%" border="1" cellpadding="5" cellspacing="0" style="border-collapse:

  collapse;" bordercolor="#111111">
    <tr>
      <td width="120" height="26" align="center">
      <b>Category</b></td>
      <td width="190" height="26" align="center">
      <b>Subcategory</b></td>
    </tr>
    <tr>
      <td width="120" align="center">
      <select size="5" name="O1_Category"

onChange="swapOptions(window.document.FrontPage_Fo rm1.O1_Category.options[selectedIndex].text

);" />
      <option>Business </option>
      <option>Household </option>
      <option>Miscellaneous </option>
      <option>Real_Estate </option>
      <option>Vehicles </option>
      </td>
      <td width="190">
      <select size="5" name="O2_Subcategory" />
       <option>Bus. Cards</option>
      <option>Employment</option>
      <option>Services</option>
      <option></option>
      <option></option>
      <option></option>
      <option></option>
      <option> .</option>
      </td>
    </tr>
  </table>

</td>
</tr>
</table>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
form submit problem/dependent list menus alexscan Pro PHP 0 January 1st, 2008 06:29 PM
Retain form value from dependent list box qhong Dreamweaver (all versions) 18 November 4th, 2004 03:36 AM
Dynamic Dependent List Box improvement SoC Classic ASP Basics 1 August 16th, 2004 01:02 AM
Retain form values qhong Javascript 1 May 13th, 2004 02:02 AM



All times are GMT -4. The time now is 02:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.