Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How is this possible that the form submit only the "input" field of the clickt table cell

<form id="switch" method="POST">
    <table>
        <tr>
            <td>some content<input type="hidden" name="switch_value" value="1"></td>
            <td>some content<input type="hidden" name="switch_value" value="2"></td>
            <td>some content<input type="hidden" name="switch_value" value="3"></td>
            <td>some content<input type="hidden" name="switch_value" value="4"></td>
            <td>some content<input type="hidden" name="switch_value" value="5"></td>
        </tr>
    </table>
</form>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
138 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this:

<form id="switch" method="POST">
    <table>
        <tr>
            <td><label>some content<input type="radio" name="switch_value" value="1"></label></td>
            <td><label>some content<input type="radio" name="switch_value" value="2"></label></td>
            <td><label>some content<input type="radio" name="switch_value" value="3"></label></td>
            <td><label>some content<input type="radio" name="switch_value" value="4"></label></td>
            <td><label>some content<input type="radio" name="switch_value" value="5"></label></td>
        </tr>
    </table>
</form>
<script>
$(document).ready(function(){
  $('#switch input[type="radio"]').change(function(){
    $('#switch').submit();
  });
});
</script>

I wrapped the text and the radio buttons between label that way, even if you use css to hide the radio buttons, the text would propagate the event down to the radio button.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...