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 8458075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:58:49+00:00 2026-06-10T12:58:49+00:00

I need help i found this tutorial for validating form without refreshing but the

  • 0

I need help i found this tutorial for validating form without refreshing but the problem is i think this is for just text fields 🙂 but i’m using 4 different radiobuttons i really need this script to work with these radiobutton !

here is the javascript file 🙂 !

runOnLoad(function(){
  $("input#name").select().focus();         
});

$(function() {        
    $('.error').hide();        
    $(".button").click(function() {  

        // validate and process form here  
        $('.error').hide(); 
        var name = $("input#name").val();  

        if (name == "") {  
            $("label#name_error").show();  
            $("input#name").focus();  
            return false;  
        }  

        var email = $("input#email").val();  
        if (email == "") {  
            $("label#email_error").show();  
            $("input#email").focus();  
            return false;  
        }  

        var mobile = $("input#mobile").val();  
        if (mobile == "") {  
            $("label#mobile_error").show();  
            $("input#mobile").focus();  
            return false;  
        }  

        var college = $("input#college").val();  
        if (college == "") {  
            $("label#college_error").show();  
            $("input#college").focus();  
            return false;  
        }  

        var university = $("input#university").val();  
        if (university == "") {  
          $("label#university_error").show();  
          $("input#university").focus();  
          return false;  
        }  

        var level = $("input#level").val();  
        if (level == "") {  
          $("label#level_error").show();  
          $("input#level").focus();  
          return false;  
        }  

        var first_preference = $("input#first_preference").val();  
            if (first_preference == "") {  
          $("label#first_preference_error").show();  
          $("input#first_preference").focus();  
          return false;  
        }  

        var second_preference = $("input#second_preference").val();  
        if (second_preference == "") {  
          $("label#second_preference_error").show();  
          $("input#second_preference").focus();  
          return false;  
        }  

        var third_preference = $("input#third_preference").val();  
        if (third_preference == "") {  
          $("label#third_preference_error").show();  
          $("input#third_preference").focus();  
          return false;  
        }  

        var heard = $("input#heard").val();  
        if (heard == "") {  
          $("label#heard_error").show();  
          $("input#heard").focus();  
          return false;  
        }     

        var applying = $("input#applying").val();  
        if (applying == "") {  
          $("label#applying_error").show();  
          $("input#applying").focus();  
          return false;  
        }    

        var strength = $("input#strength").val();  
        if (strength == "") {  
          $("label#strength_error").show();  
          $("input#strength").focus();  
          return false;  
        }   

        var weakness = $("input#weakness").val();  
        if (weakness == "") {  
          $("label#weakness_error").show();  
          $("input#weakness").focus();  
          return false;  
        }    

        var previousEx = $("input#previousEx").val();  
        if (previousEx == "") {  
          $("label#previousEx_error").show();  
          $("input#previousEx").focus();  
          return false;  
        }   



        var dataString = 'name='+ name + '&email=' + email + '&mobile=' + mobile + '&college=' + college + '&university=' + university + '&level=' + level + '&first_preference=' + first_preference + '&second_preference=' + second_preference + '&third_preference=' + third_preference + '&heard=' + heard + '&applying=' + applying + '&strength=' + strength + '&weakness=' + weakness + '&previousEx=' + previousEx;

        $.ajax({
              type: "POST",
              url: "php/database_sorting.php",
              data: dataString,
              success: function() {
                $('#contact_form').html("<div id='message'></div>");
                $('#message').html("<h2>Contact Form Submitted!</h2>")
                .append("<p>We will be in touch soon.</p>")
                .hide()
                .fadeIn(1500, function() {
                  $('#message').append("<img id='checkmark' src='images/done.png' />");
                });
              }
        });
        return false;
    });
});

DEMO:

  • 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-10T12:58:50+00:00Added an answer on June 10, 2026 at 12:58 pm

    Assuming you have a radio buttons grouped by name, to check if one of them is selected:

    //update the name to correspond to your radios group's name
    if (!$('input[type="radio"][name="radiosGroup"]:checked').length) {
        alert('no radios selected!');
        //you can adapt the error message to your liking,
        //e.g. replacing the alert with $('#radio_error').show()
        return false;
    }
    

    Fiddle


    Another way to “skip” JS validation on radio buttons is to leave one of them pre-checked when you generate the page:

    <input type="radio" name="radiosGroup" checked="checked" value="1" />
    

    This way one of the radios will always be selected.


    Using HTML5, you can use the required attribute on input elements (except button inputs) to skip JS validation for modern browsers. Fiddle


    Finally, if all your input/textarea/checkbox/radios are inside of a form, you can use jQuery’s .serialize() to generate a query string instead of building it manually. And if they aren’t inside of a form, you can wrap them inside of one.

    $('#myForm').serialize();
    

    Fiddle


    And as already commented in the question, JS validation is just to provide a better UI (e.g. showing errors without refreshing the page), you need server-side validation if you’re making your site public as JS can be easily bypassed.


    One more side-note, assuming your inputs are inside of a form, it’s better to attach your validation to the form’s .submit() handler than on a button click, to ensure that your validation will be fired whenever the form is submitted independently of browser or user clicking in the submit button or pressing Enter in a text input element.

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

Sidebar

Related Questions

I need a regex expert to help out on this one. Examples I've found
Im just new to Java and I found this good tutorial for creating a
Im just new to Java and i found this good tutorial for creating a
Need help writing a script downloads data from google insight using c# this is
I'm new to django. so I need your help. I am having a problem,
I hope you can help me with my little problem here. I'm just starting
I'm trying to install Node.JS on Windows 7 with help of this tutorial. I
Need help, function getFamily() { FB.api('/me/family', function(response) { alert(JSON.stringify(response)); }); } With the above
Need help with a query that I wrote: I have three tables Company id
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend

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.