如果使用 jquery 在表单提交中选择单选按钮,我如何需要文本框?

发布于 2024-11-17 21:42:13 字数 2668 浏览 1 评论 0原文

如果选择了第二个单选按钮,如何要求第二个文本框在提交此表单时包含一些文本?

<form action="" method="post" id="search_form" name="search_form">
                <div id="inquryValue-form-item" class="form-item">
                    <div class="form-radio display-inline">
                        <input type="radio" class="required" value="" checked="checked" id="inquryValue" name="search_value">
                    </div>
                    <div class="field-label-45-percent display-inline">
                        <label>
                            Inquiry ID
                        </label>
                    </div>
                    <div id="fepUserIDValueWrapper" class="form-radio display-inline">
                        <input type="radio" class="required" value="" id="fepUserIDValue" name="search_value">
                    </div>
                    <div class="field-label-45-percent display-inline">
                        <label id="fepUserIDValueLabel" for="fepUserIDValue">
                            FEPDirect User ID
                        </label>
                    </div>
                    <div id="inquiry_dateLabelWrapper" class="field-label-45-percent display-inline">
                        <label id="inquiry_dateLabel" for="inquiry_date">
                            Inquiry Date
                        </label>
                    </div>
                </div>
                <div id="fepUserIDValue-form-item" class="form-item">
                    <div id="Search_valueWrapper" class="form-textfield">
                        <input type="text" class="required" value="" id="search_value" name="search_value">
                    </div>
                    <div id="Inquiry_dateWrapper" class="form-textfield">
                        <input type="text" name="inquiry_date" id="inquiry_date" class="date-picker hasDatepicker">
                        <div id="search_value_labelWrapper" class="field-label">
                            <div class="field-description">
                                <span title="This field is required if entering a User ID" class="required">*</span>
                                This field is required if entering an User ID
                            </div>
                        </div>
                    </div>
                    <input type="button" id="search_inquiry-submit" class="neutral" value="Search">
                </div>
                </form>

How do I require the second text box have some text in it on the submission of this form if the second radio button is selected?

<form action="" method="post" id="search_form" name="search_form">
                <div id="inquryValue-form-item" class="form-item">
                    <div class="form-radio display-inline">
                        <input type="radio" class="required" value="" checked="checked" id="inquryValue" name="search_value">
                    </div>
                    <div class="field-label-45-percent display-inline">
                        <label>
                            Inquiry ID
                        </label>
                    </div>
                    <div id="fepUserIDValueWrapper" class="form-radio display-inline">
                        <input type="radio" class="required" value="" id="fepUserIDValue" name="search_value">
                    </div>
                    <div class="field-label-45-percent display-inline">
                        <label id="fepUserIDValueLabel" for="fepUserIDValue">
                            FEPDirect User ID
                        </label>
                    </div>
                    <div id="inquiry_dateLabelWrapper" class="field-label-45-percent display-inline">
                        <label id="inquiry_dateLabel" for="inquiry_date">
                            Inquiry Date
                        </label>
                    </div>
                </div>
                <div id="fepUserIDValue-form-item" class="form-item">
                    <div id="Search_valueWrapper" class="form-textfield">
                        <input type="text" class="required" value="" id="search_value" name="search_value">
                    </div>
                    <div id="Inquiry_dateWrapper" class="form-textfield">
                        <input type="text" name="inquiry_date" id="inquiry_date" class="date-picker hasDatepicker">
                        <div id="search_value_labelWrapper" class="field-label">
                            <div class="field-description">
                                <span title="This field is required if entering a User ID" class="required">*</span>
                                This field is required if entering an User ID
                            </div>
                        </div>
                    </div>
                    <input type="button" id="search_inquiry-submit" class="neutral" value="Search">
                </div>
                </form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱*していゐ 2024-11-24 21:42:13

试试这个:

$('#search_form').submit(function() {
    if($('#fepUserIDValue').attr("checked") == "checked" && $('#inquiry_date').val() == '') {
       alert('Required field missing');
       return false;
    }
});

Try this:

$('#search_form').submit(function() {
    if($('#fepUserIDValue').attr("checked") == "checked" && $('#inquiry_date').val() == '') {
       alert('Required field missing');
       return false;
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文