Validation is not being applied to the radio button

Link: Issue with Form

I've encountered a problem with my script that is meant to validate and submit a form, similar to this working example: Form in Working Order

Unfortunately, the script is not functioning as intended on the first link.

The JavaScript code remains unchanged:

$("form").submit(function () {
    var html = '';
    var submitme = true;
    $(':radio').each(function() {
        nam = $(this).attr('name');
        if (!$(':radio[name="'+nam+'"]:checked').length) {
            $(':radio[name="'+nam+'"]+label').addClass('error');
            if(html.indexOf(nam) < 0){
                html += nam +' group not checked' + '</br>';
            }
            submitme = false;
        }
        else {
            $(':radio[name="'+nam+'"]+label').removeClass('error');
        }
    });
    if(submitme == false){
        $('.errorDiv').empty().append(html).show().addClass('error');
    }
    else{
        $('.errorDiv').hide();
    }

    return submitme;
});

I aim to validate the form so that any unselected radio buttons are highlighted in RED and prevent form submission. Once all radio options are chosen, the form should be able to submit successfully.

In addition, I have a code snippet which disables the submit button after selection to prevent double submissions:

$("form").submit(function () {  
        var form = $(this);
        form.find("input[type=submit]").attr("disabled", "disabled")
        form.find("input[type=submit]").attr("value", "Processing...");
        // ensure user cannot hit ENTER key to submit again
        form.find("input").attr("readonly", true);
        document.body.style.cursor = "wait";
});

Can anyone suggest where to include this additional functionality within the existing jQuery code segment?

Answer №1

For the functionality to work, ensure that you include the provided code on your webpage.

The JavaScript file linked as miscScripts.js appears to be invalid.

It begins with:

<!--

// function to swap inner DIVs in homepage left content
function showDiv(div_number) {

and ends with

});
-->

It SHOULD look like this: (remove the page level comments markup)

// function to swap inner DIVs in homepage left content
function showDiv(div_number) {

and should end with

});

I couldn't locate the "submit" code in any of the files. Which file on your page contains it?

These are the links found in the source of your page:

<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="theScriptsStyles/miscScripts.js"></script>


<script type="text/javascript" src="theScriptsStyles/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="theScriptsStyles/jquery.hoverIntent.minified.js"></script>
<script type="text/javascript" src="theScriptsStyles/jquery.naviDropDown.1.0.js"></script>

EDIT2: After reviewing your code and making some assumptions about your goals, I have made some modifications to your code resulting in the following:

NOTE: I used the change event to disable red errors as the form is corrected by the user. You can use this or make adjustments as needed.

(Modified JavaScript code block)

Here is a functional example of the modified code: http://jsfiddle.net/whNtP/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method to extend my borders to the very edge?

Struggling with table borders extending to the edge on a website using master pages and CSS stylesheet. This issue requires some troubleshooting, so any help would be appreciated. The problematic website is here. I need the border under the banner menu to ...

Error Encountered: POST method not supported in ajax request using djangoIs this a

I am currently encountering an issue while trying to pass form data values through ajax. I keep getting a method not allowed error when attempting to add a comment on a blog post. The form below is located inside the blog_detail page: <form id="co ...

PHP code to create a search form with a dropdown menu

I'm currently working on developing a simple advanced search feature where users can input a keyword and select a category from a dropdown menu. The search functionality will then display results that match both the selected category and keyword in th ...

Create a layout with three columns, each containing four list items

My unordered list (ul) has 4 li's and I'm trying to create 3 columns. However, when I have 4 li's, it only displays as 2 columns. How can I achieve a layout with 3 columns and 4 li's? Additionally, I want the li elements to be arranged ...

Animate.css does not function properly when loaded locally

I'm currently using a Flask server to host an HTML file for testing purposes. Within the head of this HTML file, I have linked to a locally stored animate.min.css file (<link rel="stylesheet" type="text/css" href="{{ url_fo ...

Basic event listener function, functional in CodePen but not operating in Chrome web browser

I'm experiencing an issue where event listener functions are not working on my browser (Chrome), but they work fine on CodePen. I've been troubleshooting this for about 2 hours, and I'm seeking some insights. Can anyone help? CodePen Link: ...

Is there a way to preserve the HTML template code as it is when saving it in a cell?

Looking to store an HTML email template in a Google Sheet cell, but running into formatting issues. The code resembles this example: See sample Email HTML code The problem arises when pasting the complete email template HTML code in a cell. Upon copying ...

Sending a parameter to a form within Edge Animate

I'm facing an issue where I need to pass a variable to a form from Edge Animate. Here's the current instruction snippet: sym.$("form").append('<iframe width="100%" height="100%" src="login_PRA.php?v_id="vidn frameborder="0" scrolling="no ...

Explain the concept of paragraph spacing in Word, including how it is

When working with my ms word 2010 document, I often use the includetext-function to incorporate HTML content: { INCLUDETEXT "test.html" } Here is an example of the HTML code that I am trying to include: <html> <head> <meta http-equiv="Co ...

Extracting Data From HTML Document Specifically Targeting Table

How can I scrape the data from the table located on the far right of this page , considering that all tables on the page use the same styles and class names? I need to extract information from that specific table and display it. Any suggestions? ...

Incorporating jquery-ui in a Rails application does not lead to an error even with a fictional alias

I'm currently working on integrating the jquery-ui-rails gem into my rails application. The app is based on Spree version 3.0. $ bundle list | grep jq * jquery-rails (4.0.5) * jquery-ui-rails (5.0.5) Despite attempting various solutions in the a ...

Utilizing Multiple Checkboxes for Precision Search Refinement

Big thanks to Khalid Ali for the support provided up until now. I am currently working with an array of songs that each have descriptions, keywords, etc. I have a set of checkboxes that I want to use to refine a search. Essentially, if someone selects the ...

Unable to trigger onClick event

The button I have with the id "jump-button" is not functioning at all. When clicked, nothing happens. I have added an alert(); to the onclick attribute to test if the button is working. However, the other two buttons (next and prev) are working perfectly ...

Bootstrap modal not displaying in full view

I recently ran into some issues while using a jQuery plugin with my bootstrap modal on my website. After implementing jQuery.noConflict(), I encountered a problem where the program no longer recognized $, forcing me to replace all instances of it with jQue ...

Looking for a break in your Jquery Ajax call?

I'm encountering an issue with calling an AJAX command. The problem arises after the AJAX has successfully called the PHP page, inserted the data into the database, and the success of the AJAX call is supposed to redirect the page to somewhere else. H ...

Delete auto-generated list using handlebars JS

I have successfully created a dynamic list using Handlebars.js and its template. However, I am now facing confusion on how to remove or delete items from the list using a function or specific code. As I am new to Handlebars, I would appreciate any help. ...

Jumping CSS dropdown menu glitch

I'm facing an issue with a dropdown menu. The main problem is that the "parent" link is moving when hovered over. HTML: <ul id="nav"> <li><span>Page 1</span> <ul> <li><a>Extralong Pag ...

"Obtaining Google locations within a modal box - a step-by-step

Having trouble with my Google Places search integration in Angular 2. <input type="text" type="text" class="form-control" placeholder="Address" [ngClass]="{active:signupSubmitted && !signUpForm.controls['formatted_address'].valid}" [ ...

Internet Explorer is failing to display images

Hey there! I'm having an issue with my product listing where the images are not showing up in Internet Explorer, even though it works fine in all other browsers. Here is the code snippet for the image container: Image container: <div class="image ...

Implementing background images with jQuery

Within my coding script, there is a variable called image_src which is defined as: var image_src = 'img/test.jpg'; I attempted to set a background-image to a block using jQuery with the following code: $('#lightbox').css({ &a ...