Reputation: 464
In my ruby on rails app, I am trying to allow a user to change a field on the screen and as a result, update the database.
A user is promoted with the following screen:
<td id="sb_user-<%=server.id%>" ondblclick="changeUser(<%= server.id %>);"><%= server.sb_user %></td>
When they double click on the sb_user field, a javascript function is called and changes the field to a textbox with a simple go button:
<script type="text/javascript">
function changeUser(id) {
//Stop the auto refresh until user hits enter
clearInterval(refreshInterval);
$("#sb_user-"+id).html("<form name='user'><div class='input-append'><input name='user_input' class='span1' id='appendedInputButton' size='16' type='text'/><button class='btn' type='button'>Go!</button></form></div>");
}
</script>
When a user enters text into the textbox and clicks go, I need it so that the database field server.sb_user is updated to whatever the user entered in that field.
Anyone have suggestions on how to do this?
Upvotes: 0
Views: 214
Reputation: 8954
What you are searching for is in place editing. Theres a railscast for that:
http://railscasts.com/episodes/302-in-place-editing
Upvotes: 3