0

Hello i am developing a 5 star rating review by the radio button. this radio button doesn't work properly.I want to implement in the wordpress. Check the image. https://i.sstatic.net/UR5ED.png. This is radio button image.if visitor doesn't give any review then validation would be work. Following code doesn't work.Anyone can give me any suggestions.

Code

jQuery(document).on('click', '#sv_form', function() {

  var timeliness = jQuery('input[name="timeliness"]:checked').value;
  //var timeliness = jQuery('input[name="timeliness"]:checked').val(); 

  if (timeliness === '') {

    jQuery('#valida_error_message').text('*All above Fields are Required');

  } else {

    jQuery.ajax({
      url: ajax_url,
      type: "POST",
      dataType: "JSON",
      //cache: false,
      data: {
        'action': 'vendor_survey_form',
        'timeliness': timeliness,
      },
      success: function(data) {

        if (data.message) {
          jQuery('body #message').html('Message sent successfully');
          jQuery("form").trigger("reset");

        } else {
          jQuery('#survey_error_message').text(data);
          jQuery("form").trigger("reset");
        }

      },
      error: function(errorThrown) {
        console.log(errorThrown);
      }

    });
  }

})
<fieldset class="timeliness">
  <!-- id="no-rate" -->
  <input type="radio" id="timeliness" class="input-no-rate" name="timeliness" value="0" checked="" aria-label="No timeliness.">

  <input type="radio" id="rate1" name="timeliness" value="1" required>
  <label for="rate1">1 tstar</label>

  <input type="radio" id="rate2" name="timeliness" value="2" required>
  <label for="rate2">2 tstar</label>

  <input type="radio" id="rate3" name="timeliness" value="3" required>
  <label for="rate3">3 tstar</label>

  <input type="radio" id="rate4" name="timeliness" value="4">
  <label for="rate4">4 tstar</label>

  <input type="radio" id="rate5" name="timeliness" value="5" required>
  <label for="rate5">5 tstar</label>

  <span class="focus-ring"></span>
</fieldset>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

0

1 Answer 1

0
<script>
    $(document).ready(function () {
        jQuery(document).on('click', '#sv_form', function () {

            var timeliness = jQuery('input[name="timeliness"]:checked').value;
            //var timeliness = jQuery('input[name="timeliness"]:checked').val(); 

            if (timeliness == '') {

                jQuery('#valida_error_message').html('*All above Fields are 
    Required');

            } else {

                jQuery.ajax({
                    url: ajax_url,
                    type: "POST",
                    dataType: "JSON",
                    //cache: false,
                    data: {
                        'action': 'vendor_survey_form',
                        'timeliness': timeliness,
                    },
                    success: function (data) {

                        if (data.message) {
                            jQuery('body #message').html('Message sent 
     successfully');
                            jQuery("form").trigger("reset");

                        } else {
                            jQuery('#survey_error_message').text(data);
                            jQuery("form").trigger("reset");
                        }

                    },
                    error: function (errorThrown) {
                        console.log(errorThrown);
                    }

                });
            }
        });
    });
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

if its not work then also show where you use this id '#sv_form'
I used <input type="button" id="svform" value="Submit" class="woocommerce-Button button"> I want to implement in the wordpress @vipul

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.