使用单选按钮的Javascript this.form.submit()

问题描述 投票:1回答:1

我有我的网页星级评分系统,你可以选择星级评分(1-5),我想在有人点击任何一个星星时发送表格,但是现在,它不会发送单选按钮值,如果我检查一下,我认为是因为它在检查单选按钮之前发送了表单。有没有更好的方法来发送带有单选按钮值onclick的表单?

<form method="POST" action="/rating" accept-charset="UTF-8"><input name="_token" type="hidden" value="vySkIFDPujcmxjfs83m3OwojcbPIaHuuMhKvVErx">

        <input name="movie_id" type="hidden" value="2">


        <input id="star5" name="rating" type="radio" value="5">
        <label for="star5" class="full" title="Awesome" onclick="this.form.submit()"> </label>


        <input id="star4" name="rating" type="radio" value="4">
        <label for="star4" class="full" title="Good" onclick="this.form.submit()"> </label>


        <input id="star3" name="rating" type="radio" value="3">
        <label for="star3" class="full" title="Mediocre" onclick="this.form.submit()"> </label>


        <input id="star2" name="rating" type="radio" value="2">
        <label for="star2" class="full" title="Bad" onclick="this.form.submit()"> </label>


        <input id="star1" name="rating" type="radio" value="1">
        <label for="star1" class="full" title="Horrible" onclick="this.form.submit()"> </label>

        </form>
javascript php html html5 webpage
1个回答
1
投票

改为在onchange元素上使用<input />

<form method="POST" action="/rating" accept-charset="UTF-8"><input name="_token" type="hidden" value="vySkIFDPujcmxjfs83m3OwojcbPIaHuuMhKvVErx">

  <input name="movie_id" type="hidden" value="2">

  <label for="star5" class="full" title="Awesome">
<input id="star5" name="rating" type="radio" value="5" onchange="this.form.submit()">
  </label>

  <label for="star4" class="full" title="Good">
<input id="star4" name="rating" type="radio" value="4" onchange="this.form.submit()">
  </label>

  <label for="star3" class="full" title="Mediocre">
<input id="star3" name="rating" type="radio" value="3" onchange="this.form.submit()">
  </label>

  <label for="star2" class="full" title="Bad">
<input id="star2" name="rating" type="radio" value="2" onchange="this.form.submit()">
  </label>

  <label for="star1" class="full" title="Horrible">
<input id="star1" name="rating" type="radio" value="1" onchange="this.form.submit()">
  </label>

</form>
© www.soinside.com 2019 - 2024. All rights reserved.