473,387 Members | 1,532 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,387 software developers and data experts.

restoring selections in radio buttons

110 100+
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.screenOne.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 1552
acoder
16,027 Expert Mod 8TB
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 100+
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 Expert Mod 8TB
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
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...
4
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>...
6
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 ...
18
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...
2
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...
1
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...
2
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...
1
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 ...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.