Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Try...Catch on radio button selection

    I've got a function that returns the value of a radio button group. However the application allows to "hide" some groups on others responses and that effectively make the radio groups not exist. This causes issues with calculations using the total value of the groups combined. I need a way to return a value of '0.00' IF the function does not find the group/returns an error.This is what I currently got to but doesnt work. The function does not work at all.
    Code:
    function  funcRadioCalc(RadioName)
    {
    var chkList1= document.getElementById (RadioName);
    var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
    var bob;
    try {
    	for( var i=0;i<arrayOfCheckBoxes.length;i++){
    		if (arrayOfCheckBoxes[i].checked) {
    		bob= arrayOfCheckBoxes[i].value;
    		if (bob!=undefined||bob!=""){
    			throw "yep";
    		}else{
    			throw "nope";
    		}
    	}
    }
    catch (er){
    	if(er=="nope")
        {
        	return "0.00";
        }
      if(er=="yep")
        {
    		return bob;
    	}
    }
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Show your HTML.

    Your JavaScript doesn't make sense.

    Why would you use [icode]chkList1.getElementsByTagName("input");[/code] to get the array of checkboxes???? That will *ALSO* get all your radio buttons *AND* all your <input type=text> and even your <input type=button> and <input type=submit>.

    I would toss that code and start over, but only after seeing what your <form> looks like...*all* fields in the <form>.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is part of a module in DotNetNuke. I have access to the JS file but not to the HTML. The form module allows for different question types and for the Radio group ut receives 2 values. The label and the value (premium,10.95) etc.

    The JS that comes with the module to return the value to a hidden field for calculations is below. However this does not compensate for the event that a question is "hidden". When that event fires the radio group effectivly no longer exists and this screws up the calculations as the field receiving the value simply retains the old value before "hiding" rather than reset to 0 (or some other default)

    So below is what I had to work with. I'm not a coder but can reverse engineer to a degree but this has me stumped.

    Code:
    function  funcRadioCalc(RadioName)
    
     {
    var chkList1= document.getElementById (RadioName);
    var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
    for(var i=0;i<arrayOfCheckBoxes.length;i++)
    {
    
    if (arrayOfCheckBoxes[i].checked) {
    return arrayOfCheckBoxes[i].value;
    }
      }
    }

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    So bring up the page in your browser.

    Click on the VIEW menu of your browser.

    Click on the SOURCE or PAGE SOURCE menu item.

    The HTML of the page will appear in an editor (MSIE) or window (FF/Chrome).

    Copy paste the *relevant* portions of the HTML here.

    If it's not too big, post everything from the <form> to the </form>. If that's too much, try to copy/paste a good sample of the various fields in the form.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I pulled out the fields that are associated:
    Code:
    <tbody>
      <tr>
        <td class="DynamicRegistration_Maintable" vAlign="bottom" colSpan="2">
          <table id="dnn_ctr424_DynamicRegistration_tblQuestions" border="0" cellSpacing="1" cellPadding="1" width="100%">
            <tbody>
              <tr id="dnn_ctr424_DynamicRegistration_b6c5df40-f395-43bf-84b9-c6f2ef5d0826" vAlign="Top">
                <td class="NormalBold" vAlign="Top" rowSpan="1" width="150" colSpan="1" align="Left">
                  <label id="dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_label"> <a id="dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_cmdHelp" tabIndex="-1" onclick="if (__dnn_Help_OnClick('dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_pnlHelp')) return false;" href="javascript:__doPostBack('dnn$ctr424$DynamicRegistration$Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826$cmdHelp','')"><img style="border-width: 0px;" id="dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_imgHelp" tabIndex="-1" alt="Please select the option" src="/images/help.gif"></a> <span id="dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_lblUserLabel">Listing Type:</span> </label>
                  <br>
                  <div style="display: none;" id="dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_pnlHelp" class="Help"> <span id="dnn_ctr424_DynamicRegistration_Label_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_lblHelp">Please select the option</span> </div>
                </td>
                <td vAlign="Top" rowSpan="1" colSpan="1">
                  <table>
                    <tbody>
                      <tr vAlign="Top">
                        <td noWrap="nowrap">
                          <table style="width: 200px;" id="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826" class="NormalTextBox" onclick="document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUID474c0640-7317-4aee-a65d-fcdb8abebad7totalBusPlan').value = funcRadioCalc('dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826');
    document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUIDa51aa1e5-871b-41a9-8391-9bb25dca3010busGrandTotal').value = parseFloat(document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUID474c0640-7317-4aee-a65d-fcdb8abebad7totalBusPlan').value) + parseFloat(document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUIDf95c7a8b-b272-4dfb-8f75-02251c4ebe7dtotalBusUp').value);;" border="0">
                            <tbody>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_0" onclick="javascript:setTimeout('__doPostBack(\'dnn$ctr424$DynamicRegistration$Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826$0\',\'\')', 0)" name="dnn$ctr424$DynamicRegistration$Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826" value="0.00" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_0">Free</label>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_1" onclick="javascript:setTimeout('__doPostBack(\'dnn$ctr424$DynamicRegistration$Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826$1\',\'\')', 0)" name="dnn$ctr424$DynamicRegistration$Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826" value="10.00" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_1">Standard ($10.00)</label>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_2" name="dnn$ctr424$DynamicRegistration$Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826" value="80.00" CHECKED="checked" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_b6c5df40-f395-43bf-84b9-c6f2ef5d0826_2">Enhanced ($85.00)</label>
                                </td>
                              </tr>
                            </tbody>
                          </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
              <tr id="dnn_ctr424_DynamicRegistration_dbb45744-241c-42ea-8515-b7ada4976b0e" vAlign="Top">
                <td class="NormalBold" vAlign="Top" rowSpan="1" width="150" colSpan="1" align="Left">
                  <label id="dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_label"> <a id="dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_cmdHelp" tabIndex="-1" onclick="if (__dnn_Help_OnClick('dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_pnlHelp')) return false;" href="javascript:__doPostBack('dnn$ctr424$DynamicRegistration$Label_dbb45744-241c-42ea-8515-b7ada4976b0e$cmdHelp','')"><img style="border-width: 0px;" id="dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_imgHelp" tabIndex="-1" alt="Please enter a value for the field Select an Upgrade." src="/images/help.gif"></a> <span id="dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_lblUserLabel">Select an Upgrade:</span> </label>
                  <br>
                  <div style="display: none;" id="dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_pnlHelp" class="Help"> <span id="dnn_ctr424_DynamicRegistration_Label_dbb45744-241c-42ea-8515-b7ada4976b0e_lblHelp">Please enter a value for the field Select an Upgrade.</span> </div>
                </td>
                <td vAlign="Top" rowSpan="1" colSpan="1">
                  <table>
                    <tbody>
                      <tr vAlign="Top">
                        <td noWrap="nowrap">
                          <table style="width: 200px;" id="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e" class="NormalTextBox" onclick="document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUIDf95c7a8b-b272-4dfb-8f75-02251c4ebe7dtotalBusUp').value = funcRadioCalc('dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e'); 
    document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUIDa51aa1e5-871b-41a9-8391-9bb25dca3010busGrandTotal').value = parseFloat(document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUID474c0640-7317-4aee-a65d-fcdb8abebad7totalBusPlan').value) + parseFloat(document.getElementById('dnn_ctr424_DynamicRegistration_TBR_GUIDf95c7a8b-b272-4dfb-8f75-02251c4ebe7dtotalBusUp').value);;" border="0">
                            <tbody>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_0" name="dnn$ctr424$DynamicRegistration$Responses_dbb45744-241c-42ea-8515-b7ada4976b0e" value="0.00" CHECKED="checked" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_0">None</label>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_1" name="dnn$ctr424$DynamicRegistration$Responses_dbb45744-241c-42ea-8515-b7ada4976b0e" value="10.00" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_1">Bronze ($10.00)</label>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_2" name="dnn$ctr424$DynamicRegistration$Responses_dbb45744-241c-42ea-8515-b7ada4976b0e" value="50.15" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_2">Silver ($30.00)</label>
                                </td>
                              </tr>
                              <tr>
                                <td>
                                  <input id="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_3" name="dnn$ctr424$DynamicRegistration$Responses_dbb45744-241c-42ea-8515-b7ada4976b0e" value="85.00" type="radio">
                                  <label for="dnn_ctr424_DynamicRegistration_Responses_dbb45744-241c-42ea-8515-b7ada4976b0e_3">Gold ($50.00)</label>
                                </td>
                              </tr>
                            </tbody>
                          </table>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
              <tr id="dnn_ctr424_DynamicRegistration_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d" vAlign="Top">
                <td class="NormalBold" vAlign="Top" rowSpan="1" width="150" colSpan="1" align="Left">
                  <label id="dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_label"> <a id="dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_cmdHelp" tabIndex="-1" onclick="if (__dnn_Help_OnClick('dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_pnlHelp')) return false;" href="javascript:__doPostBack('dnn$ctr424$DynamicRegistration$Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d$cmdHelp','')"><img style="border-width: 0px;" id="dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_imgHelp" tabIndex="-1" alt="Please enter a value for the field totalBusUp." src="/images/help.gif"></a> <span id="dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_lblUserLabel">totalBusUp:</span> </label>
                  <br>
                  <div style="display: none;" id="dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_pnlHelp" class="Help"> <span id="dnn_ctr424_DynamicRegistration_Label_f95c7a8b-b272-4dfb-8f75-02251c4ebe7d_lblHelp">Please enter a value for the field totalBusUp.</span> </div>
                </td>
                <td vAlign="Top" rowSpan="1" colSpan="1">
                  <table>
                    <tbody>
                      <tr vAlign="Top">
                        <td vAlign="Top">
                          <input style="width: 200px;" id="dnn_ctr424_DynamicRegistration_TBR_GUIDf95c7a8b-b272-4dfb-8f75-02251c4ebe7dtotalBusUp" class="NormalTextBox" name="dnn$ctr424$DynamicRegistration$TBR_GUIDf95c7a8b-b272-4dfb-8f75-02251c4ebe7dtotalBusUp" maxLength="50" value="0.00" type="text">
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
              <tr id="dnn_ctr424_DynamicRegistration_474c0640-7317-4aee-a65d-fcdb8abebad7" vAlign="Top">
                <td class="NormalBold" vAlign="Top" rowSpan="1" width="150" colSpan="1" align="Left">
                  <label id="dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_label"> <a id="dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_cmdHelp" tabIndex="-1" onclick="if (__dnn_Help_OnClick('dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_pnlHelp')) return false;" href="javascript:__doPostBack('dnn$ctr424$DynamicRegistration$Label_474c0640-7317-4aee-a65d-fcdb8abebad7$cmdHelp','')"><img style="border-width: 0px;" id="dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_imgHelp" tabIndex="-1" alt="Please enter a value for the field totalBusPlan." src="/images/help.gif"></a> <span id="dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_lblUserLabel">totalBusPlan:</span> </label>
                  <br>
                  <div style="display: none;" id="dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_pnlHelp" class="Help"> <span id="dnn_ctr424_DynamicRegistration_Label_474c0640-7317-4aee-a65d-fcdb8abebad7_lblHelp">Please enter a value for the field totalBusPlan.</span> </div>
                </td>
                <td vAlign="Top" rowSpan="1" colSpan="1">
                  <table>
                    <tbody>
                      <tr vAlign="Top">
                        <td vAlign="Top">
                          <input style="width: 200px;" id="dnn_ctr424_DynamicRegistration_TBR_GUID474c0640-7317-4aee-a65d-fcdb8abebad7totalBusPlan" class="NormalTextBox" name="dnn$ctr424$DynamicRegistration$TBR_GUID474c0640-7317-4aee-a65d-fcdb8abebad7totalBusPlan" maxLength="50" value="80.00" type="text">
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>     
              <tr id="dnn_ctr424_DynamicRegistration_a51aa1e5-871b-41a9-8391-9bb25dca3010" vAlign="Top">
                <td class="NormalBold" vAlign="Top" rowSpan="1" width="150" colSpan="1" align="Left">
                  <label id="dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_label"> <a id="dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_cmdHelp" tabIndex="-1" onclick="if (__dnn_Help_OnClick('dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_pnlHelp')) return false;" href="javascript:__doPostBack('dnn$ctr424$DynamicRegistration$Label_a51aa1e5-871b-41a9-8391-9bb25dca3010$cmdHelp','')"><img style="border-width: 0px;" id="dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_imgHelp" tabIndex="-1" alt="Please enter a value for the field busGrandTotal" src="/images/help.gif"></a> <span id="dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_lblUserLabel">busGrandTotal:</span> </label>
                  <br>
                  <div style="display: none;" id="dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_pnlHelp" class="Help"> <span id="dnn_ctr424_DynamicRegistration_Label_a51aa1e5-871b-41a9-8391-9bb25dca3010_lblHelp">Please enter a value for the field busGrandTotal</span> </div>
                </td>
                <td vAlign="Top" rowSpan="1" colSpan="1">
                  <table>
                    <tbody>
                      <tr vAlign="Top">
                        <td vAlign="Top">
                          <input style="width: 200px;" id="dnn_ctr424_DynamicRegistration_TBR_GUIDa51aa1e5-871b-41a9-8391-9bb25dca3010busGrandTotal" class="NormalTextBox" name="dnn$ctr424$DynamicRegistration$TBR_GUIDa51aa1e5-871b-41a9-8391-9bb25dca3010busGrandTotal" maxLength="50" value="80" type="text">
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
            </tbody>
          </table>
        </td>
        <td vAlign="bottom" colSpan="2"></td>
      </tr>
    </tbody>

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    And that JS code makes no sense at all.
    Code:
    function  funcRadioCalc(RadioName)
    {
        // (1) The variable is "RadioName" and yet you use it in getElementById()
        // (2) The code never even uses chkList1
        // (3) Which is good, because it's bound to be wrong
        var chkList1= document.getElementById (RadioName);
    
        // As I noted, this next line will get an array of *ALL* input elements:
        // checkboxes, radio buttons, buttons, etc.
        var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
        for(var i=0;i<arrayOfCheckBoxes.length;i++)
        {
            // this will return ONLY ONE value...so it's worthless for actually 
            // testing an array of checkboxes.  In any case, it will find the *FIRST*
            // checked item of *ANY* kind:  radio button, checkbox.  NO MATTER
            // WHAT the name of the input is!
            if (arrayOfCheckBoxes[i].checked) { return arrayOfCheckBoxes[i].value; }
        }
    }
    So I dunno where you got that code from, but I wouldn't use that source any more.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Deleted for doubled up post
    Last edited by turvak; 08-31-2011 at 03:36 PM. Reason: Deleted for doubled up post

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Ugh. DotNetNuke continues to produce some of the ugliest code in the world.

    It's truly bizarre. The click on the <table> that *holds* the group of radio buttons is what invokes the funcRadioCalc() js function which I *assume* is the culprit here.

    The onclick on the radio buttons themselves SUBMIT THE FORM back to the server!

    So there's no real purpose at all in doing the funcRadioCalc(). If you are going to run back to the server on every button click (typically crappy ASP.NET coding...not entirely ASP.NET's fault, as so many people just leave the automatic postback settings in place because they don't understand why they shouldn't), then why not just do *ALL* the calculations in the ASP.NET code??? Instead, some idiot decided to use the radio button values to plunk something into the text fields and then let the ASP.NET code work from those values. *SIGH* Neither fish nor fowl, but the worst of *BOTH* worlds.

    The RIGHT thing to do would be to fix the ASP.NET code. But if you have no clue how to do that, then you will have to show us the *EXISTING* code for funcRadioCalc( )

    I *THINK* it can be written as simply as this:
    Code:
    function  funcRadioCalc(RadioName)
    {
        var rbs = document.forms[0][RadioName];
        if ( rbs == null ) return 0; // the "trick" to return 0 if field doesn't exist
        for ( var r = 0; r < rbs.length; ++r )
        {
            if ( rbs[r].checked ) return rbs[r].value;
        }
        return 0;
    }
    But I'd much rather see the original code to be sure.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That does look more logical. And yes I hear a lot about .NET coders that get stuck doing things the "old and tired" ways. Maybe PHP was the way to go but I now have so many clients using the DNN system that I have to continue supporting it. *sigh* But thank you so far for your assistance, It's great to have solid community forums.
    Here is the original code
    Code:
    /*original*/
    function  funcRadioCalc(RadioName)
    
     {
    var chkList1= document.getElementById (RadioName);
    var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
    for(var i=0;i<arrayOfCheckBoxes.length;i++)
    {
    
    if (arrayOfCheckBoxes[i].checked) {
    return arrayOfCheckBoxes[i].value;
    }
      }
    }

  • #10
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This only returns the 0 value and not the radio value.
    function funcRadioCalc(RadioName)
    {
    var rbs = document.forms[0][RadioName];
    if ( rbs == null ) return 0; // the "trick" to return 0 if field doesn't exist
    for ( var r = 0; r < rbs.length; ++r )
    {
    if ( rbs[r].checked ) return rbs[r].value;
    }
    return 0;
    }

  • #11
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This only returns the 0 value and not the radio value.
    function funcRadioCalc(RadioName)
    {
    var rbs = document.forms[0][RadioName];
    if ( rbs == null ) return 0; // the "trick" to return 0 if field doesn't exist
    for ( var r = 0; r < rbs.length; ++r )
    {
    if ( rbs[r].checked ) return rbs[r].value;
    }
    return 0;
    }
    I got your code to work using:
    Code:
    function  funcRadioCalc(RadioName)
    {
    	var chkList1= document.getElementById (RadioName);
    	var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
    	if ( arrayOfCheckBoxes == null) return "hidden buttons default"; //this did not work
    	for(var i=0;i<arrayOfCheckBoxes.length;i++)
    	{
    		if (arrayOfCheckBoxes[i].checked) {
    			return arrayOfCheckBoxes[i].value;
    		}
    	}
    	return "no selection default"; //this worked
    }
    I think the null check is not working because when the radio group is hidden the ID effectively does not exist so it has nothing to reference as you can see from the call:
    Code:
    $(totalBusPlan) = funcRadioCalc($(busPlan_FieldID)); //radio group 1
    $(totalBusUp) = funcRadioCalc($(busUp_FieldID)); //radio group 2 that can be HIDDEN - this is the problem point
    $(busGrandTotal) = parseFloat($(totalBusPlan)) + parseFloat($(totalBusUp)); //returns NaN when the above is hidden as the value does not exist

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    I give up. The code still makes no sense.

    This line is TOTALLY USELESS:
    Code:
    	var chkList1= document.getElementById (RadioName);
    as I pointed out twice before. Even if it worked (it won't...it will always get a null value except maybe in MSIE), the variable chkList1 is *NEVER* used, so there is no point in it at all.

    In any case, I *still* think the right answer is to fix the badly written ASP.NET code. But never mind, if you are happy, you are happy.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •