使用JQuery不传递选定的单选按钮值

时间:2012-09-12 18:48:16

标签: jquery

我用它来将一些字段的值收集到一个字段中。除了单选按钮值之外,一切都正常传递。

 jQuery('#donate-form').submit(function() {
 jQuery('[name="COMMENT2"]').val('Donation: ' + jQuery('.active [name="USER2"]').val() + ': ' + jQuery('input[name="reason"]:checked').val() + ': ' + jQuery('[name="sponsorName"]').val() + 
                ' Occasion: ' + jQuery('.active [name="occasion"]').val() + ' Donated By: ' + jQuery('.active [name="donatedBy"]').val() + ' Use: ' + jQuery('input[name="day"]:checked').val() + 
                ' Date: ' + jQuery('[name="date"]').val() + ' Contact Me: ' + jQuery('[name="contactMe"]').val()); 
 });

HTML                    

<div class="row"><label for="amount">Amount:</label><input id="amount 2" name="AMOUNT" type="text" class="required"/><br/></div>
    <div class="row">
        <input name="reason" type="radio" id="memory" value="In Memory of" /><label for="memory">In Memory of</label>
        <input name="reason" type="radio" id="honor" value="In Honor of"/><label for="honor">In Honor of</label>
        <input name="reason" type="radio" id="noOccasion" value="No Occasion"/><label for="noOccasion">No Occasion</label>
    <br/></div>
    <div class="row"><label for="sponsorName">Name(s):</label>
        <input id="sponsorName" name="sponsorName" type="text"/><br/></div>
    <div class="row"><label for="occasion">Occasion:</label>
        <input id="occasion" name="occasion" type="text"/><br/></div>
    <div class="row"><label for="donatedBy">Donated By:</label>
        <input id="donatedBy" name="donatedBy" type="text"/><br/></div>
    <div class="row">Make a request to reserver your special day:</div>
    <div class="row">
        <input name="day" type="radio" id="English" value="English Date"/>
            <label for="English">English Date</label>
        <input name="day" type="radio" id="Hebrew" value="Hebrew Date"/>
            <label for="Hebrew">Hebrew Date</label>
    </div>
    <div class="row"><label for="date">Date:</label>
        <input id="date" name="date" type="text"/><br/></div>
    <div class="row"><input type="checkbox" name="contactMe" value="yes" id="contactMe" /><label class="long" for="contactMe">Contact me for acknowledgement notices.</label></div>
    <div class="row"><label for="comments">Comments</label><textarea id="comments" name="COMMENT1" cols="38" rows="1" style="margin-left:0"></textarea></div>
    <input type="hidden" name="COMMENT2" value=""></input><input type="hidden" name="DESCRIPTION"></input>
  </form>

1 个答案:

答案 0 :(得分:0)

此代码何时运行?您尝试从单选按钮获取值的方式应该可以正常运行,假设您只需要检查值...

我已经设置了基本演示here来展示这一点。只需点击“英语日期”单选按钮即可查看其实际效果。