473,898 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

restoring selections in radio buttons

110 New Member
I have a webpage that uses visible and hidden tables to create the effect of going from screen to screen. Because a user might want to go back and change previous selections I have a "previous page" button that goes back to a table that has been made hidden. Text fields retain their values; but, option buttons do not. I am having problems restoring the original selections to the option buttons. I can post the code; but, the javascript functions are very long. If I have a pair of option buttons where the options are Yes and No I assign values to the variable names based on whether or not the "checked" option is true (eg: document.screen One.nearWater[0].checked=true;) . However when I go back to the "page" I cannot restore the original selection by reversing the process. For example, using the example above, if option "0" is "No" the following code does not produce the correct result.
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('nearWater').value=="No"){
  2. document.screenOne.nearWater[0].checked=true;
  3. } else if(document.getElementById('nearWater').value=="Yes"){
  4. document.screenOne.nearWater[1].checked=true;
  5. }
  6.  
How can I restore the original selections to radio buttons?
Feb 10 '09 #1
3 1580
acoder
16,027 Recognized Expert Moderator MVP
If the "page" (div/table) is simply hidden (probably by setting style.display), then it shouldn't affect any elements within the container element. Can you show the code for when you hide a container element, e.g. the function called when clicking Next.
Feb 10 '09 #2
andersond
110 New Member
This is the code for the first "page"

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script type="text/javascript">
  3. <!-- 
  4. function question(x){
  5.     var itemNumber = x; // question number
  6.  
  7. ...
  8.  
  9.     if(x=="1"){
  10.         var y = document.getElementById('pState'); 
  11.         var z = y.options[y.selectedIndex].value; //value from dropdown
  12.         document.getElementById('propertyST').value = z;
  13.  
  14.         if (z=='IN' || z=='IL' || z=='KY' || z=='MO' || z=='OH' || z=='TN'){
  15.             status="ELIGIBLE";
  16.         } else {
  17.             status="REFERRED";
  18.         }
  19.  
  20.             if(document.getElementById('pState').value=="AL"){
  21.                 document.getElementById('propertyState').value="Alabama";
  22.             } else if(document.getElementById('pState').value=="AZ"){
  23.                 document.getElementById('propertyState').value="Arizona";
  24.             } else if(document.getElementById('pState').value=="AR"){
  25.                 document.getElementById('propertyState').value="Arkansas";
  26.             } else if(document.getElementById('pState').value=="CA"){
  27.                 document.getElementById('propertyState').value="California";
  28.             } else if(document.getElementById('pState').value=="CO"){
  29.                 document.getElementById('propertyState').value="Colorado";
  30.             } else if(document.getElementById('pState').value=="CT"){
  31.                 document.getElementById('propertyState').value="Connecticut";
  32.             } else if(document.getElementById('pState').value=="DE"){
  33.                 document.getElementById('propertyState').value="Delaware";
  34.             } else if(document.getElementById('pState').value=="DC"){
  35.                 document.getElementById('propertyState').value="District of Columbia";
  36.             } else if(document.getElementById('pState').value=="FL"){
  37.                 document.getElementById('propertyState').value="Florida";
  38.             } else if(document.getElementById('pState').value=="GA"){
  39.                 document.getElementById('propertyState').value="Georgia";
  40.             } else if(document.getElementById('pState').value=="ID"){
  41.                 document.getElementById('propertyState').value="Idaho";
  42.             } else if(document.getElementById('pState').value=="IL"){
  43.                 document.getElementById('propertyState').value="Illinois";
  44.             } else if(document.getElementById('pState').value=="IN"){
  45.                 document.getElementById('propertyState').value="Indiana";
  46.             } else if(document.getElementById('pState').value=="IA"){
  47.                 document.getElementById('propertyState').value="Iowa";
  48.             } else if(document.getElementById('pState').value=="KS"){
  49.                 document.getElementById('propertyState').value="Kansas";
  50.             } else if(document.getElementById('pState').value=="KY"){
  51.                 document.getElementById('propertyState').value="Kentucky";
  52.             } else if(document.getElementById('pState').value=="LA"){
  53.                 document.getElementById('propertyState').value="Louisiana";
  54.             } else if(document.getElementById('pState').value=="ME"){
  55.                 document.getElementById('propertyState').value="Maine";
  56.             } else if(document.getElementById('pState').value=="MD"){
  57.                 document.getElementById('propertyState').value="Maryland";
  58.             } else if(document.getElementById('pState').value=="MA"){
  59.                 document.getElementById('propertyState').value="Massachusetts";
  60.             } else if(document.getElementById('pState').value=="MI"){
  61.                 document.getElementById('propertyState').value="Michigan";
  62.             } else if(document.getElementById('pState').value=="MN"){
  63.                 document.getElementById('propertyState').value="Minnesota";
  64.             } else if(document.getElementById('pState').value=="MS"){
  65.                 document.getElementById('propertyState').value="Mississippi";
  66.             } else if(document.getElementById('pState').value=="MO"){
  67.                 document.getElementById('propertyState').value="Missouri";
  68.             } else if(document.getElementById('pState').value=="MT"){
  69.                 document.getElementById('propertyState').value="Montana";
  70.             } else if(document.getElementById('pState').value=="NC"){
  71.                 document.getElementById('propertyState').value="North Carolina";
  72.             } else if(document.getElementById('pState').value=="ND"){
  73.                 document.getElementById('propertyState').value="North Dakota";
  74.             } else if(document.getElementById('pState').value=="NE"){
  75.                 document.getElementById('propertyState').value="Nebraska";
  76.             } else if(document.getElementById('pState').value=="NH"){
  77.                 document.getElementById('propertyState').value="New Hampshire";
  78.             } else if(document.getElementById('pState').value=="NJ"){
  79.                 document.getElementById('propertyState').value="New Jersey";
  80.             } else if(document.getElementById('pState').value=="NM"){
  81.                 document.getElementById('propertyState').value="New Mexico";
  82.             } else if(document.getElementById('pState').value=="NM"){
  83.                 document.getElementById('propertyState').value="New Mexico";
  84.             } else if(document.getElementById('pState').value=="NY"){
  85.                 document.getElementById('propertyState').value="New York";
  86.             } else if(document.getElementById('pState').value=="OH"){
  87.                 document.getElementById('propertyState').value="Ohio";
  88.             } else if(document.getElementById('pState').value=="OK"){
  89.                 document.getElementById('propertyState').value="Oklahoma";
  90.             } else if(document.getElementById('pState').value=="OR"){
  91.                 document.getElementById('propertyState').value="Oregon";
  92.             } else if(document.getElementById('pState').value=="PA"){
  93.                 document.getElementById('propertyState').value="Pennsylvania";
  94.             } else if(document.getElementById('pState').value=="RI"){
  95.                 document.getElementById('propertyState').value="Rhode Island";
  96.             } else if(document.getElementById('pState').value=="SC"){
  97.                 document.getElementById('propertyState').value="South Carolina";
  98.             } else if(document.getElementById('pState').value=="SD"){
  99.                 document.getElementById('propertyState').value="South Dakota";
  100.             } else if(document.getElementById('pState').value=="TN"){
  101.                 document.getElementById('propertyState').value="Tennessee";
  102.             } else if(document.getElementById('pState').value=="TX"){
  103.                 document.getElementById('propertyState').value="Texas";
  104.             } else if(document.getElementById('pState').value=="UT"){
  105.                 document.getElementById('propertyState').value="Utah";
  106.             } else if(document.getElementById('pState').value=="VT"){
  107.                 document.getElementById('propertyState').value="Vermont";
  108.             } else if(document.getElementById('pState').value=="VA"){
  109.                 document.getElementById('propertyState').value="Virginia";
  110.             } else if(document.getElementById('pState').value=="WA"){
  111.                 document.getElementById('propertyState').value="Washington";
  112.             } else if(document.getElementById('pState').value=="WV"){
  113.                 document.getElementById('propertyState').value="West Virginia";
  114.             } else if(document.getElementById('pState').value=="WI"){
  115.                 document.getElementById('propertyState').value="Wisconsin";
  116.             } else if(document.getElementById('pState').value=="WO"){
  117.                 document.getElementById('propertyState').value="Wyoming";
  118.             }
  119.             document.getElementById('tableCompletionFeedback').background="Images/completionBLUE3%.jpg";
  120.             document.getElementById('percent').innerHTML="3% complete";
  121.  
  122.             document.getElementById('propST').value=document.getElementById('pState').value;
  123.             document.getElementById('percent').style.fontFamily="Arial Narrow"; 
  124.             document.getElementById('percent').style.fontSize="10pt";
  125.             document.getElementById('percent').align="right";
  126.  
  127.             document.getElementById('tableRecap').style.visibility="visible";
  128.  
  129.             document.getElementById('cellOutput01').style.height="10";
  130.             document.getElementById('cellOutput02').style.height="10";
  131.             document.getElementById('cellOutput03').style.height="10";
  132.             document.getElementById('cellOutput04').style.height="10";
  133.             document.getElementById('cellOutput05').style.height="10";
  134.  
  135.             document.getElementById('cellOutput01').style.fontFamily="Arial Narrow"; 
  136.             document.getElementById('cellOutput01').style.fontSize="10pt";
  137.             document.getElementById('cellOutput01').innerHTML="Property is located in "+document.getElementById('propertyState').value;
  138.             document.screenOne.pState.style.backgroundColor="#FFFFFF";
  139.  
  140.             document.screenOne.nearWater1.disabled = false;
  141.             document.screenOne.nearWater2.disabled = false;
  142.  
  143.             document.getElementById('nearWater1').focus();
  144.         }
  145.  
  146.     if(x=="2"){
  147.             document.getElementById('tableCompletionFeedback').background="Images/completionBLUE6%.jpg";
  148.             document.getElementById('percent').innerHTML="6% complete";        
  149.             document.getElementById('nearWater').value=document.getElementById('nearH2O').value;
  150.  
  151.             document.getElementById('percent').style.fontFamily="Arial Narrow"; 
  152.             document.getElementById('percent').style.fontSize="10pt";
  153.             document.getElementById('percent').align="right";
  154.  
  155.             document.getElementById('cellOutput02').style.fontFamily="Arial Narrow"; 
  156.             document.getElementById('cellOutput02').style.fontSize="10pt";
  157.             var limit=document.screenOne.nearH2O.length;
  158.             for (i=0;i<limit;i++) {
  159.             if (document.screenOne.nearH2O[0].checked==true) { // NO
  160.                 status="REFERRED";
  161.                 document.getElementById('cellOutput02').innerHTML="Property is not located within 10 miles of an ocean, bay, or waterway";
  162.             } else if (document.screenOne.nearH2O[1].checked==true) { // YES
  163.                 document.getElementById('cellOutput02').innerHTML="Property is located within 10 miles of an ocean, bay or waterway";
  164.                 }
  165.             }
  166.             document.screenOne.mVacant.disabled = false;
  167.             document.screenOne.mVacant.style.border="1px solid #003300"; 
  168.             scroll(0,0);
  169.             document.screenOne.mVacant.focus();
  170.         }
  171.  
  172.     if(x=="3"){
  173.             document.getElementById('tableCompletionFeedback').background="Images/completionBLUE9%.jpg";
  174.             document.getElementById('percent').innerHTML="9% complete";             
  175.             document.getElementById('monthsVacant').value=document.getElementById('mVacant').value;
  176.             document.getElementById('cellOutput03').style.fontFamily="Arial Narrow"; 
  177.             document.getElementById('cellOutput03').style.fontSize="10pt";
  178.             document.getElementById('cellOutput03').innerHTML="Property has been vacant "+rtrim(document.getElementById('monthsVacant').value)+" months";
  179.             if(document.getElementById('mVacant').value > 24){status="REFERRED"}
  180.             document.getElementById('percent').style.fontFamily="Arial Narrow"; 
  181.             document.getElementById('percent').style.fontSize="10pt";
  182.             document.getElementById('percent').align="right";
  183.  
  184.             document.screenOne.mVacant.style.backgroundColor="#FFFFFF";
  185.             document.screenOne.bankrupt1.disabled = false;
  186.             document.screenOne.bankrupt2.disabled = false;
  187.             document.getElementById('bankrupt1').focus();
  188.         }
  189.  
  190.       if(x=="4"){
  191.             document.getElementById('tableCompletionFeedback').background="Images/completionBLUE12%.jpg";
  192.             document.getElementById('percent').innerHTML="12% complete";      
  193.             document.getElementById('bankruptcy').value=document.getElementById('bankrupt').value;
  194.             document.getElementById('percent').style.fontFamily="Arial Narrow"; 
  195.             document.getElementById('percent').style.fontSize="10pt";
  196.             document.getElementById('percent').align="right";
  197.  
  198.             document.getElementById('cellOutput04').style.fontFamily="Arial Narrow"; 
  199.             document.getElementById('cellOutput04').style.fontSize="10pt";
  200.  
  201.             var limit=document.screenOne.bankrupt.length;
  202.             for (i=0;i<limit;i++) {
  203.             if (document.screenOne.bankrupt[0].checked==true) { // NO
  204.                 status="REFERRED";
  205.                 document.getElementById('cellOutput04').innerHTML="Risk has never filed bankruptcy";
  206.             } else if (document.screenOne.bankrupt[1].checked==true) { // YES
  207.                 document.getElementById('cellOutput04').innerHTML="Risk has a previous bankruptcy";
  208.                 }
  209.             }
  210.             document.getElementById('cD1').disabled = false;
  211.             document.getElementById('cD2').disabled = false;
  212.             document.getElementById('cD3').disabled = false;
  213.  
  214.             document.getElementById('desiredCoverage').focus();
  215.         }
  216.  
  217.       if(x=="5"){
  218.             document.getElementById('tableCompletionFeedback').background="Images/completionBLUE15%.jpg";
  219.             document.getElementById('percent').innerHTML="15% complete";             
  220.             document.getElementById('percent').style.fontFamily="Arial Narrow"; 
  221.             document.getElementById('percent').style.fontSize="10pt";
  222.             document.getElementById('percent').align="right";
  223.  
  224.             document.getElementById('cellOutput05').style.fontFamily="Arial Narrow"; 
  225.             document.getElementById('cellOutput05').style.fontSize="10pt";
  226.             var limit=document.screenOne.desiredCoverage.length;
  227.             for (i=0;i<limit;i++) {
  228.                 if (document.screenOne.desiredCoverage[0].checked==true) { // Property ONLY
  229.                     document.getElementById('coverageDesired').value="property";
  230.                     document.getElementById('tablePropertyCoverage').style.visibility="visible";
  231.                     document.getElementById('cellOutput05').innerHTML="Applicant has requested property coverage ONLY";
  232.  
  233.                 } else if (document.screenOne.desiredCoverage[1].checked==true) { // Liability ONLY
  234.                     document.getElementById('coverageDesired').value="liability";
  235.                     document.getElementById('tableLiabilityCoverage').style.visibility="visible";
  236.                     document.getElementById('cellOutput05').innerHTML="Applicant has requested liability coverage ONLY";
  237.  
  238.                 } else if (document.screenOne.desiredCoverage[2].checked==true) { // both
  239.                     document.getElementById('coverageDesired').value="both";
  240.                     document.getElementById('tablePropertyCoverage').style.visibility="visible";
  241.                     document.getElementById('tableLiabilityCoverage').style.visibility="visible";
  242.                     document.getElementById('cellOutput05').innerHTML="Applicant has requested both Property and Liability coverage";
  243.                 }
  244.             }
  245.             document.screenOne.B1.disabled = false;  
  246.             scroll(0,0);
  247.             document.getElementById('B1').focus();
  248.         }
  249.  
Here's the code for the first "continue" button and the swapnode function.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript; version=1.5">
  2. Node.prototype.swapNode = function (node) {
  3.   var nextSibling = this.nextSibling;
  4.   var parentNode = this.parentNode;
  5.   node.parentNode.replaceChild(this, node);
  6.   parentNode.insertBefore(node, nextSibling);
  7.   }  
  8. </script>
  9.  
  10. if(x=="clear1"){
  11.   document.getElementById('tableContainer1').swapNode   document.getElementById('tableContainer0'));
  12. document.getElementById('tableContainer1').style.visibility="hidden";
  13. document.getElementById('tableContainer0').style.visibility="visible";
  14. document.getElementById('tableContainer0').style.visibility="visible";
  15. document.getElementById('insuredName').focus();
  16.             }
  17.  
And, here's the code for the first previous page button

Expand|Select|Wrap|Line Numbers
  1. function previousPage(x){// returns user to the previous page
  2.     if(x=='P1'){
  3.                 document.getElementById('tableContainer1').swapNode(document.getElementById('tableContainer0'));
  4.                 document.getElementById('tableContainer0').style.visibility="hidden";
  5.                 document.getElementById('tableContainer1').style.visibility="visible";
  6.                 if(document.getElementById('nearH2O').value=="NO"){
  7.                     document.screenOne.nearH2O[0].checked=true;
  8.                 } else if(document.getElementById('nearH2O').value!="NO"){
  9.                     document.screenOne.nearH2O[1].checked=true;
  10.                 }
  11.                 setTimeout("document.getElementById('pState').focus()",100);
  12.         }
  13.  
I know you didn't expect this much code; but the whole script section is 1658 lines.
Feb 10 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
I'm not sure why you're using swapNode here and why the radio buttons are reset, but the problem can be solved by getting the set of elements and then indexing them:
Expand|Select|Wrap|Line Numbers
  1. var nearH2Oval = document.getElementById('nearH2O').value;
  2. var nearH2O = document.screenOne.nearH2O;
  3. if (nearH2Oval == "NO") {
  4.     nearH2O[0].checked=true;
  5. } ...
Feb 11 '09 #4

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

Similar topics

7
1906
by: NotGiven | last post by:
I'd like to have several levels of field selection. For example, field one has three choices. Once you choose on form field one, several selections show in field based that ARE BASED ON your selection in field one. Field three selections are based on field two,... If you know of a good tutorial or site recommendations, I' appreciate you posting them here. Thanks.
4
3287
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1> <input type="radio" name=p2 value=2> <input type="radio" name=p2 value=3> then a text area and a button:
6
3299
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked The problem i am facing is that i do not know how many yes/no radio groups will be generated
18
3358
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those columns, "scode" and "sname", as 1 column (if not possible then 2 columns will be fine) in the listbox. Can the listbox display 2 columns information from the dataset and how can I do that? Also, I set the property of the listbox to selectionmode...
2
11994
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put them each in a GroupBox. All the examples I saw from the books or from the web show me how to add static radio buttons at design, or dynamically at run time but with fixed radio buttons (like from an array). I need to create radio buttons based...
1
6897
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
2
2419
by: brad | last post by:
Group, I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which contains nested server user controls in order to create a tree-like hierarchy. The tree is a sort of question and answer dialog. The user answers a question, and the next subquestion appears (using dynamic html display:none|block) depending on his answer.
1
1933
by: scanreg | last post by:
My form needs to (1) direct to specified URLs based on a combination of form selections and (2) enable/disable form features based on selections within the form FORM Radio 1 - A - B - C Select Box 1
2
5899
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on the form by changing the visible state of the radio buttons and labels utilising back and next buttons. E.g. Next button makes current radio buttons and labels invisible and
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9842
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11265
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10487
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8036
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5882
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4708
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.