You are viewing limited content. For full access, please sign in.

Question

Question

If then else based on date and dropdown fields field

asked on October 21, 2016

I'm trying to set up code so that I can show or hide the submit button based on any type of field, single line, radio button, dropdown, checkbox, signature field.  I've gotten the code to work for all but the dropdown field and the date field.

Here is what is working:

$(document).ready(function () {

var $submit = $('.Submit');
  var $single = $('#Field1');
  var $radio = $('#Field2');

// bind to radio button
  $($radio).click(function () {

  if($('input[value="RB1"]').is(':checked'))

  {

  $submit.show();

  }
    else
    {
      $submit.hide();
    }

      });


  //bind single line
$($single).on("change", function() {

         if ($(this).val() !== " "){

            $submit.show();

         } else {

             $submit.hide();

         }

     });
 
  //bind to signature
  $('.Sign_Sig').click(function () {
     $('.Submit').show(); //show the submit button after signing

   });
  $(document).on('click','.form-sig-remove',function(){

     $('.Submit').hide(); //hide the submit button if the signature is removed

   });

 });

 

but when I try to bind to either a date or dropdown field it doesn't work...  Here is my date code:

Date field is "q5"

//bind to date

$('#q5').on ("change", function(){

if($(this).val() !== ""){

 $submit.show();

         } else {

             $submit.hide();

         }

     });

 

And my dropdown field is Field4 or "q4"

Here is my code for that:

//bind event handler to the dropdown field
  $('#Field4').change(function() {

    //if the user selects what we want, show the submit button
    if ('$Field4 selected').val() === "Dropdown 1"){
     
      $submit.show();
    }
    //if not, hide it
    else {
     
      $submit.hide();
    }
  });

 

When I put either of these two sections of code in my JavaScript, the submit button always is shown.

Help?

0 0

Answer

SELECTED ANSWER
replied on October 24, 2016

Here is the code that finally worked for my dropdown field:

  //bind event handler to the dropdown field
    $("#q4").on("change", function(){
     var check = $("#Field4").val();
      if (check !== "") {
    
    $submit.show();
    }
    //if not, hide it
    else {
      
      $submit.hide();
    }
  });
 

1 0

Replies

replied on October 22, 2016

Katy,

 

In the date field, try ("#q5 input").val.  For the dropdown section, you are just missing the other closing parentheses after "Dropdown 1".  The condition enclosure parentheses is never completed.

0 0
replied on October 24, 2016

New bind to date code that still doesn't work:

$("#q5").on("change", function(){
   if($(this).val() != " "){
    $submit.show();
    }
        else
    {
    $submit.hide();
    }
  });
  

replied on October 24, 2016

Thank you.  This worked for date:

  $('#q5').on("change", function(){
   if($("#q5 input").val() != ""){
    $submit.show();
    }
        else
    {
    $submit.hide();
    }
  });
But it doesn't hide it if the date is deleted...

 

0 0
replied on January 16, 2018

I'm struggling to get it to work for just the signature. I'm not sure what I'm doing wrong.

0 0
replied on June 13, 2018

Here is my code for binding to signature...

$(document).ready(function () {
 //code goes here 
  //cache the elements we will use
  var $submit = $('.Submit');

//bind to signature
  $('.Sign_Sig').click(function () { 
     $('.Submit').show(); //show the submit button after signing 

   }); 
  $(document).on('click','.form-sig-remove',function(){ 

     $('.Submit').hide(); //hide the submit button if the signature is removed 

   }); 
  

  
   
 });

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.