Update Input Value With jQuery, Old Value Submitted to Form

Posted by Tyler DeWitt on Stack Overflow See other posts from Stack Overflow or by Tyler DeWitt
Published on 2012-09-28T21:32:19Z Indexed on 2012/09/28 21:37 UTC
Read the original article Hit count: 198

Filed under:
|
|
|

I've got a form with an input with id/name league_id

<form accept-charset="UTF-8" action="/user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="?"><input name="authenticity_token" type="hidden" value="bb92urX83ivxOZZJzWLJMcr5ZSuamowO9O9Sxh5gqKo="></div>
    <input id="league_id" name="league_id" type="text" value="11">
    <select class="sport_selector" id="sport_type_id" name="sport_type_id"><option value="5" selected="selected">Football</option>
    <option value="25">Women's Soccer</option>
    <option value="30">Volleyball</option>
    <option value="10">Men's Soccer</option></select>
    <input name="commit" type="submit" value="Save changes">
</form>

In another part of my page, I have a drop down that, when changed, clears the value of league_id

$("#sport_type_id").change ->
$("#league_id").val(null)
$(this).parents('form:first').submit()

If I debug this page, I can see the value get wiped from the text box, but when the form is submitted, my controller always gets the old value.

I tried changing the name of the input and got the same results.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html