开发者

Unable to retrieve the value checked button in radio button group

I am trying to retrieve the value of the checked button in a radio button group.

    <script type="text/javascript">

function ButtonClicked() {

    alert($('input[name=datetype] :checked').val());
    return;
}

</script>

<f开发者_开发技巧orm action="test.php">

<input type="radio" value="d1" name="datetype" checked onclick="javascript: ButtonClicked()">Date 1 <br />
<input type="radio" value="d2" name="datetype" onclick="javascript: ButtonClicked()"> Date 2 <br />

</form>

The output is always 'undefined' . I am a beginner to jQuery(and JS) so I may be missing something obvious but looking at tons of examples didn't help.


alert($('input[name=datetype]:checked').val()); try without a space


Remove 'javascript' from onclick.

<input type="radio" value="d1" name="datetype" checked onclick="ButtonClicked()">Date 1 <br />
<input type="radio" value="d2" name="datetype" onclick="ButtonClicked()"> Date 2 <br />


much easyser:

<script type="text/javascript">
  function ButtonClicked(value) {
    alert(value);
    return;
 }

</script>
<form action="test.php">
<input type="radio" value="d1" name="datetype" checked onclick="javascript:ButtonClicked(this.value)">Date 1 <br />
<input type="radio" value="d2" name="datetype" onclick="javascript: ButtonClicked(this.value)"> Date 2 <br />
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜