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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:37:02+00:00 2026-06-09T02:37:02+00:00

Hello I have been trying to make this form work with no luck, So

  • 0

Hello I have been trying to make this form work with no luck, So in submit if the textarea is empty and any of the radio button are not being selected trow a message for both, if textarea has text but a radio is not being selected trow a second message, if radio button is being selected but textarea is empty display a third message and last if both textarea has text and a radio button is being selected display a success message.

This is my html:

                <div id="main" role="main">

                <form action="?q=dt-index" method="post" name="subscribeForm" id="myform">

                    <div id="comment_holder" class="input_holder" style="position: relative;">
                        <textarea rows="6" cols="30" placeholder="Please enter text" name="comment" class="inp"></textarea>
                    </div>

                    <div class="cbox">
                        <input type="radio" name="smile_selected" value="Awesome" id="yummy1" />
                            <label for="yummy1" class="yummy">Awesome</label>
                        <input type="radio" name="smile_selected" value="Good" id="cool1" />
                            <label for="cool1" class="cool">Good</label>
                        <input type="radio" name="smile_selected" value="Okay" id="ok1" />
                            <label for="ok1" class="ok_smile">Okay</label>
                        <input type="radio" name="smile_selected" value="Yuck" id="yuck1" />
                            <label for="yuck1" class="yuck">Yuck</label>
                    </div>

                    <div id="loading_button">
                        <button type="submit" class="default">Send</button>
                    </div>

                </form>

                <div id="errors"></div> <!-- Error container -->

            </div>

This is my jQuery:

                $(document).ready(function() {


            /* on submitting my form */
                $( '#myform' ).submit(function() {

            /*          if Textarea is empty and redio button are not checked display message error for both */
                        if($('#myform textarea').val()=="")
                        {
                             if (!$(":radio:checked").attr('checked')) {
                                 $('#errors').empty().text('Please enter your message and select a radio'); 
                                return false;
                             }  
                        }

            /*          else if Textarea is empty display message error */
                        else if($('#myform textarea').val()=="") {  
                            $('#errors').empty().text('Please enter your message');
                            return false;
                    }

            /*          if radio button is not being selected display message error */
                        if (!$(":radio:checked").attr('checked')) {
                            $('#errors').empty().text('Please select a radio');
                            return false;
                    }

            /*          Everthing is good display success message and add SENDING class to submit button */
                        else {
                            $('#myform :submit').addClass('sending').html('Sending message...');
                            $('#errors').empty().text('All Good :D');
                        }
                });
            });
  • 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-09T02:37:03+00:00Added an answer on June 9, 2026 at 2:37 am

    Your if statement logic is kind of redundant, and it allowed only a radio button to selected, because you forgot to add an “else” before the 3rd “if”. But here is a better way to do it, that is also expandable:

    $(document).ready(function() {
    
    
            /* on submitting my form */
                $( '#myform' ).submit(function() {
    
                   var errors = [];
    
            /*     else if Textarea is empty display message error */
                   if($('#myform textarea').val()=="") {  
                        errors[errors.length] = 'enter your message';
                    }
    
            /*      if radio button is not being selected display message error */
                    if (!$(":radio:checked").attr('checked')) {
                       errors[errors.length] = 'select a radio';
                    }
    
                    if(errors.length > 0){
                        var errMsg = "Please  "
    
                        for(e = 0; e < errors.length-1; e++){
                            errMsg += errors[e]+", ";
                        }
    
                         errMsg = errMsg.substr(0, errMsg.length -2)+" and "+errors[errors.length-1]+".";
                         $('#errors').empty().text(errMsg);
                         return false;
                    }
    
            /*          Everthing is good display success message and add SENDING class to submit button */
                        else {
                            $('#myform :submit').addClass('sending').html('Sending message...');
                            $('#errors').empty().text('All Good :D');
                        }
    
                });
            });​
    

    Heres a link to show it works: http://jsfiddle.net/66CHS/

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

Sidebar

Related Questions

Have been struggling all day trying to make this simple example work using socket.io.
So I have been trying for hours to get this to work and I
Hi I have been trying to make a show/hide toggle button with jquery but
I have been trying this for the whole day and I managed to make
Hello I have been trying to send an email in magento with out a
Hello guys, I have been trying to implement the DSUM function but failed to
Hello I have been having trouble with this for a while now. I have
hello i have this question i was trying to find a way to call
Hello i have been trying to find a tutorial that show how to setup
I have been trying to teach myself MEF, starting with this tutorial: http://blogs.msdn.com/b/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx There

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.