admin管理员组

文章数量:1431675

After click the button "Delete", How to display an alert if none of radio button is selected. My html form

<form name="Action" method="post" action="RequestAction">
                    <table width="800px" cellpadding="5" style="color:black; border-top:1px solid #ccc;" border="0">
                    </table>
                    <div id="container">
                    <div id="demo_jui">
                    <table id="requestList" class="display" cellpadding="0" cellspacing="0" border="0" style="font-size:12px;" >
                    <thead id="headed">
                        <tr>
                            <th  align="center" title="Employee">Employee</th>
                            <th  align="center" title="Number of Days">Number of Days</th>
                            <th  align="center" title="Start Date">Start Date</th>
                            <th  align="center" title="End Date">End Date</th>
                            <th  align="center" title="Leave Type">Leave Type</th>
                            <th  align="center" title="Remark">Remark</th>
                            <th  align="center">Approve</th>
                            <th  align="center">Reject</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                    </table>
                    </div>
                    </div>
                        <table>                 
                        <tr>
                            <td style="padding-left:0px;" colspan="3">
                                <a href="#"><img src="images/Submit.png" style="border:none;" onClick="javascript:Go()"
                                onmouseover="this.src='images/Submit_Hover.png'" onmouseout="this.src='images/Submit.png'"/></a>
                                &nbsp;&nbsp;&nbsp;
                                <a href="#"><img src="images/Reset.png" style="border:none;" onClick="javascript:clearForm()"
                                onmouseover="this.src='images/Reset_Hover.png'" onmouseout="this.src='images/Reset.png'"/></a>
                            </td>
                        </tr>
                    </table>
                </form>

The radio button value will be retrieved in table. When I test it, if click submit button without select any radio button, i will get error

In function Go(), is the way validate radio button correct? Thank you

function Go() {
                if( $('form[name=Action] input[name=statusList]:checked').length == 0)
                {
                    $('form[name=Action]').submit();
                }
                else
                {
                    alert("Please select at least one to delete");
                }
            }

After click the button "Delete", How to display an alert if none of radio button is selected. My html form

<form name="Action" method="post" action="RequestAction">
                    <table width="800px" cellpadding="5" style="color:black; border-top:1px solid #ccc;" border="0">
                    </table>
                    <div id="container">
                    <div id="demo_jui">
                    <table id="requestList" class="display" cellpadding="0" cellspacing="0" border="0" style="font-size:12px;" >
                    <thead id="headed">
                        <tr>
                            <th  align="center" title="Employee">Employee</th>
                            <th  align="center" title="Number of Days">Number of Days</th>
                            <th  align="center" title="Start Date">Start Date</th>
                            <th  align="center" title="End Date">End Date</th>
                            <th  align="center" title="Leave Type">Leave Type</th>
                            <th  align="center" title="Remark">Remark</th>
                            <th  align="center">Approve</th>
                            <th  align="center">Reject</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                    </table>
                    </div>
                    </div>
                        <table>                 
                        <tr>
                            <td style="padding-left:0px;" colspan="3">
                                <a href="#"><img src="images/Submit.png" style="border:none;" onClick="javascript:Go()"
                                onmouseover="this.src='images/Submit_Hover.png'" onmouseout="this.src='images/Submit.png'"/></a>
                                &nbsp;&nbsp;&nbsp;
                                <a href="#"><img src="images/Reset.png" style="border:none;" onClick="javascript:clearForm()"
                                onmouseover="this.src='images/Reset_Hover.png'" onmouseout="this.src='images/Reset.png'"/></a>
                            </td>
                        </tr>
                    </table>
                </form>

The radio button value will be retrieved in table. When I test it, if click submit button without select any radio button, i will get error

In function Go(), is the way validate radio button correct? Thank you

function Go() {
                if( $('form[name=Action] input[name=statusList]:checked').length == 0)
                {
                    $('form[name=Action]').submit();
                }
                else
                {
                    alert("Please select at least one to delete");
                }
            }
Share Improve this question edited Jan 8, 2013 at 8:09 user1944535 asked Jan 3, 2013 at 3:31 user1944535user1944535 432 silver badges5 bronze badges 1
  • Your HTML doesn't appear to have any checkbox or inputs at all. Also, your JavaScript appears to be backwards in that your conditional is only submitting when there are NO checked inputs. Also, the Java and exception stack trace are not relevant to the question. – Andrew Hubbs Commented Jan 3, 2013 at 3:40
Add a ment  | 

2 Answers 2

Reset to default 3

Maybe the check for "checked" status doesn't work?

//read value of radio button
alert($("input[name='radio-button-group']:checked").val());

//get bool, if radio button is checked
alert(typeof $("input[name='radio-button-group']:checked").val() != 'undefined');

Source (german): http://mabraham.de/jquery-radio-buttons-auslesen-und-manipulieren/

use the below snippet

var IsChecked = $('take id or classname of radiogroup').is(':checked');

if(!IsChecked)
{
alert("select some thing");
}

本文标签: javascriptShow alert() if no radio button is selectedStack Overflow