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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:46:10+00:00 2026-06-12T03:46:10+00:00

How do I make :confirm=>Are you sure conditional? I have this code <div id=container><%=

  • 0

How do I make :confirm=>”Are you sure” conditional?
I have this code

<div id="container"><%= form_for @question,:remote=>true,:html=>{:name=>"question"} do |f|%>
    <p>
        <div class ="row">
        <%= label_tag(:topic,@displayquestion.question_text,:class=>"form-label")%>
        </div>
    </p>
    <p>
    <label>
    <%= f.radio_button(:answer, "1") %>
    <%= label_tag(:choice1,@displayquestion.choice1,:class=>"form-label")%>
    </label>
    </p>
    <p>
    <label>
    <%= f.radio_button(:answer, "2") %>
    <%= label_tag(:choice2,@displayquestion.choice2,:class=>"form-label")%>
    </label>
    </p>
    <p>
    <label>
    <%= f.radio_button(:answer, "3") %>
    <%= label_tag(:choice3,@displayquestion.choice3,:class=>"form-label")%>
    </label>
    </p>
    <p>
    <label>
    <%= f.radio_button(:answer, "4") %>
    <%= label_tag(:choice4,@displayquestion.choice4,:class=>"form-label")%>
    </label>
    </p>
    <%= f.submit(:value=>next,:class =>"button",:disable_with=>'loading') %>
<% end %></div>

I want to make it such that it will prompt only if no radio button is selected.
I have this jQuery code which will prompt the user if no radio button was selected.

$(document).ready(function(){

   $("#container").on("click", ".edit_question", function(event){

     if (!$("input[@name='question[answer]']:checked").val()) {
       confirm('Are sure you want to submit a blank answer?');
    }

   if (!$("input[@name='answer[]']:checked").val()) {
       confirm('Are sure you want to submit a blank answer?');
    }

}
);
});

The problem is that even when I click cancel, the ajax request is sent, how do intercept the ajax request to call the jQuery code?

Thanks for the pointer!
I did it this way and it works!

$(document).ready(function(){

   $("#container").on("submit", ".edit_question", function(event){
    var reply = true;
     if (!$("input[@name='question[answer]']:checked").val()) {
       reply=confirm('Are sure you want to submit a blank answer?');
    }

   if (!$("input[@name='answer[]']:checked").val()) {
       reply=confirm('Are sure you want to submit a blank answer?');
    }
   return reply;
}
);
});
  • 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-12T03:46:11+00:00Added an answer on June 12, 2026 at 3:46 am

    Your click function needs to return false to cancel the page submission. confirm() returns a bool, true for ok, false for cancel.

    Example:

    $("#container").on("click", ".edit_question", function(event){
    
        if (!$("input[@name='question[answer]']:checked").val()
            || !$("input[@name='answer[]']:checked").val()  ) {
            return confirm('Are sure you want to submit a blank answer?');
        }
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make sure that $ is always referencing jQuery , I code in this
I have OnClientClick=return confirm('Make Payment?'); tied to an asp:Button. It works fine, however, prior
i make one class file for jar. and this class have use wurfl. and
I'm using the following code to make sure fields are filled in. How can
I have an application and I'm trying to make sure it's running in a
Can someone confirm my suspicion on this line of code. NSUInteger newPath[] = {[indexPath
This is my code: <input type=submit value=Delete onclick=del('Are you sure you want to Delete?')>
I am trying to make a confirm box which will desire which php code
How can I make this run at server? javascript: function confirm_delete() { if (confirm(Are
i have a button where i need the a confirm popup. this is like

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.