Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8333359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:00:25+00:00 2026-06-09T03:00:25+00:00

So I have this form, sent via jQuery ajax, but I’d like to validate

  • 0

So I have this form, sent via jQuery ajax, but I’d like to validate the fields. I know how to validate the normal input fields, but the radio buttons and checkboxes are causing trouble. Here’s my code that validates the form and sends it, and displays the result.

$(function() {
    $("#submit").click(function() {
var kysymys1 = $.trim($("input.kysymys1").val());
      if (kysymys1 == "") {
          alert('Täytä kaikki kentät.');
          return false;
      }
var kysymys2 = $.trim($("input.kysymys2").val());
      if (kysymys2 == "") {
          alert('Täytä kaikki kentät.');
          return false;
      }
var kysymys3 = $.trim($("input.kysymys3").val());
      if (kysymys3 == "") {
          alert('Täytä kaikki kentät.');
          return false;
      }

      var dataString = $('#service-test').serialize();
      //alert (dataString);return false;
     $.ajax({
    type: "POST",
    url: "../quiz.php",
    data: dataString,
    dataType: "text",
    error: function(){ alert ('Nyt jotakin meni kyllä pahemman kerran pieleen. Yritä uudelleen?');
 },
    success: function(data) {
 $("#result").html(data);
$('#service-test').fadeOut('slow');
   }


  });
  return false;

    });
  });        

And the form itself:

<div style="border:1px solid grey;">
<div id="result" style="padding:2%;"></div>
<form id="service-test" action="#" method="../quiz.php" style="padding:2%;">
Muuttuuko sivujen sisältö usein?
<input type="radio" name="muuttuminen" value="Kylla" class="kysymys1" /> Kyllä
<input type="radio" name="muuttuminen" value="Ei" class="kysymys1" />Ei
Mitä näistä voisit haluta sivuillesi?
<input type="checkbox" name="possiblecontent" value="Kuvagallerian"  class="kysymys2" />Kuvagallerian
<input type="checkbox" name="possiblecontent" value="Pieni verkkokauppa"  class="kysymys2" />Pieni verkkokauppa
<input type="checkbox" name="possiblecontent" value="Isompi verkkokauppa"  class="kysymys2" />Isompi verkkokauppa
<input type="checkbox" name="possiblecontent" value="Jotain muuta"  class="kysymys2" />Jotain muuta
Millaisen ulkoasun haluaisit?
<input type="radio" name="ulkoasu" value="Massasta erottuvan, uniikin ulkoasun"  class="kysymys4" /> Massasta erottuvan, uniikin ulkoasun
<input type="radio" name="ulkoasu" value="Jotain muuta"  class="kysymys3" /> Jotain muuta
<input id="submit" type="submit" /></form>
</div>

However, the validation part doesn’t do anything if user wont choose.

Here’s a jsfidde too:
http://jsfiddle.net/ducVP/4/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:00:27+00:00Added an answer on June 9, 2026 at 3:00 am

    In stead of checking the value, you want to check if the checkbox/radio button has been selected..

    So try this

    if ($('input.kysymys1:checked').val() == 'false') {
              alert('Täytä kaikki kentät.');
              return false;
    }
    

    This checks if the checkbox is checked, and if it isn’t then it does the alert.

    Edit
    Why not just have one of the radio buttons checked as default?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form and when this form is sent via AJAX, I display
I have form which data will be sent via ajax. It is normal string-type
I have this form: <tbody> <tr> <th>ID</th> <th>Name</th> <th>Birthdate</th> <th><input type=text autofocus=autofocus name=textinput1/></th> <th><input
I have this Form I am trying to upload my image but every time
I have this form with a date input. echo $this->Form->create('Nodata'); echo $this->Form->input('date1', array('type' =>
I have this form: <form> <div class=box> <h1>Contact form :</h1> <label> <span>Typ: </span> <input
I have a form, in which I need to send data selected via AJAX
I have successfully used ajax to refresh in-line, via ajax, a contact form. I'm
I have a web page containing a login form which loads via HTTP, but
I have a form. This form submits via POST to an iframe, that, in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.