开发者

manipulating radio box selection with javascript

i'm trying to do a poll but i designed it without any radio box in it. So i decided to make the selection being highlighted with a different background color, all is done with jquery.

I set the display of the radio box to none so that it wouldn't show, gave each a unique ID. Here's the script.

<form action="v_poll.php" method="post">
<ul class="voting">
<li class="voting votetext"><input type="radio" name="voting" value="a1" style="display:none;" id="a1"><a onClick="vote('a1')"Answer 1</a></li>
<li class="voting votetext"><input type="radio" name="voting" value="a2" style="display:none;" id="a2"><a onClick="vote('a2')">Answer 2</a></li>
<li class="voting votetext"><input type="radio" name="voting" value="a3" style="display:none;" id="a3"><a onClick="vote('a3')">Answer 3</a></li>
<input type="hidden" value="1" name="id" />
<input type="submit" value="submit">
</ul>
</form>
<script type="text/javascript">
function vote(TheValue) {
GetElementById(TheValue).ch开发者_JAVA百科ecked=true;
}
</script>

But when i checked the value of the radio box with $_POST['voting'], it is blank. Not the value assigned to the radio box. Anything i'm doing wrong?

Please help. Thanks.


You can do this without javascript as well, using a <label> with for="id" instead of <a>, like this:

<li class="voting votetext">
  <input type="radio" name="voting" value="a1" style="display:none;" id="a1">
  <label for="a1">Answer 1</label>
</li>

This is nothing new/HTML5 or anything, any browser IE6+, and probably older will support this.


GetElementById(TheValue).checked=true;

should instead be:

document.getElementById(TheValue).checked=true;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜