I am attempting to submit a HTML form that has some values created via javascript. However, when I submit the form those input fields lose their values in favor of empty strings. What can I do to prevent the fields from dropping their new values upon hitting the submit button?
Form Code:
Form Code:
Output:<form id="post-form" class="save-form" method="POST" action="/posts" style="display: none">
<input placeholder="Title" name="title" /><br>
<input placeholder="Location" name="location" /></br>
<input placeholder="Content" name="content" /><br>
<input id="formlat" name="latitude" type="hidden" />
<input id="formlng" name="longitude" type="hidden" />
<input name="user_id" type="hidden" value="<%= current_user.id %>" />
<input type="submit" value="Submit"/>
</form>
Relevant Javascript Code:Output:var newlat = newmarker.getPosition().lat();
var newlng = newmarker.getPosition().lng();
document.getElementById("formlat").value = newlat;
document.getElementById("formlng").value = newlng;
Setting default values, or not setting them, always produces the same result: the form submits with "" for those fields (or whatever was inside value=""). However, the console shows that those fields are correctly being filled with their lat/long up until I hit the submit button, where they revert to their default values (in this case ""). It is only in rails' logs that I can see the fields are blank in the actual POST.User has been warned for this post. Reason: No BBcode, Multiple threads