Thursday, February 27, 2020

JQUERY - GET SELECTED TEXT AND VALUE





ERROR Handling for COMBO BOX or SELECTED BOX -

<select size="1" id="cmbSTHour" name="cmbSTHour" class="recordData">
<option selected value="0"></option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
</select>

Get the selected value
$('#cmbSTHour').val() == 0

Get the Selected Text
$('#cmbSTHour option:selected').text()

Tuesday, February 11, 2020

JAVASCRIPT, JQUERY ERROR HANDLING - KEEP IT SIMPLE



Part of Keeping things simple is coding yourself.... You don't have to use frameworks to do SIMPLE things..... Here is a Javascript, Jquery error handler on a button click,. Calls a servlet on the server....... KIS!

//GLOBAL VARIABLES

var G_MSGTITLE;
G_MSGTITLE = "_________________________________________\n\n";
G_MSGTITLE += "CLIENT VALIDATION ERRORS\n";
G_MSGTITLE += "This form was not submitted because of the following error(s). \n";
G_MSGTITLE += "Please correct these error(s) and re-submit.\n";
G_MSGTITLE += "_________________________________________\n\n";

var G_MSG;


/**
*   Function Name:  setloadVCvoucherrecord()
*   Description :   Sets the jQuery controls
*   Parameters:     None.
*   Return:         None.
*/
function setloadVCvoucherrecord(){

    $(document).ready(function() {

        //BUTTON TO GO TO UPDATE Cancer Care Agreement
        $('#UpdateCCA').click( function () {
         
            try{
                var fileIndex = 0;
                G_MSG = "";

                $.each(table3.row('.selected').data(), function(index, value){

                    if ( index===0 ){
                        fileIndex = value;
                    }

                });             

                //Add Parameter to form
                $("#CCAfileIndex").val(fileIndex);                                               

                if (fileIndex === 0 ){
                    G_MSG += "Error - No file selected.\n";
                }
             
                if (G_MSG.length > 0)
                    throw G_MSG;
             
                //Keep Form on Same window
                $('#frmVoucherRecord').on('submit',function(){
                   $(this).attr("target", "_parent");
                   $(this).attr( "action", "UpdateCancerCareAgreement");
                });               

            }catch( err ){

                alert(G_MSGTITLE + err );
                return false;

            }             
         
    });     
        //END OF BUTTON TO GO TO UPDATE Cancer Care Agreement
     }); 

}