1
0
-1

Dear Team,


I am facing problem in JavaScript, i have two radio button option called "Days" and "Hours".

when we press the Days it should use this formula for calculate the Days 

---------------------

 $('input[name="from_date"], input[name="to_Date"]').change( function(){
      d1 = $('input[name="from_date"]').datepicker('getDate');
      d2 = $('input[name="to_Date"]').datepicker('getDate');
      diff = 0;
      if (d1 && d2)
          {
            diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000)+1; // ms per day
      }
      $('input[name=Enter_Number_of_Days_Hours]').val(diff);
});

------------------------------------


and when we click on the Hours i want to clear the text from this ID "Enter_Number_of_Days_Hours" so that the user can enter the number of hours .


can you please help me with JavaScript for this. as i have tried all the place could not find the suitable solution for joget





    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hi Dear,


      I have applied your solution but still when i click on the radio button it dose no clear the text from the field. 

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi, 

        you can use jQuery to achieve this. below is sample code, please modify it according to your requirements

        $('input[type="radio"]').click(function() {
            // Get the value of the selected radio button
            var selectedValue = $('input[type="radio"]:checked').val();
            if( selectedValue == 'Hours') {
        	  $('input[name=Enter_Number_of_Days_Hours]').val('');	
        	}
            console.log(selectedValue + " selected");
          });


        Hopefully this will resolve the issue.

          CommentAdd your comment...