开发者

input[type=text] submit different value than displayed

I am developing an app using Rails and jQuery. I would like to submit an id integer value via an input form but still display a friendly text value to the user while he is filling out the form. The text input field is using jQuery autocomplete so once the user chooses an entry, an integer value will be put into the input field. Is there any way to di开发者_Python百科splay a different value from what is actually submitted?


Alternatively, you can also keep a hidden input field, and use a "change" event to keep the hidden input field updated every time the user changes the original field.


Try using the combobox functionality for the jQuery UI Autocomplete:

http://jqueryui.com/demos/autocomplete/#combobox

The value attribute of the options are what get sent along with the form, not the display text.


I understand what you want to do. I have done the same thing for a drop down. Never tried for a text box though!:( What I did was that the dropdown displayed name of entries in database and when user submits the form,the ID in the database is passed. I hope thats precisely what you want. I am putting the code for the same below. I know this is not what you are looking for but it may give you a hint !

In the view:

<%= f.select :facilitator_group_id, FacilitatorGroup.all.map { |fg| [fg.name, fg.id] } %>

FacilitatotGroup is my model name.

Cheers !

Hi.I also feel that the reason we use textfield is for user to enter data which they wanna store in DB. For your reason, why cant you use a dropdown ?


You can use

$('myform').submit(function() { /* your thing here */ });

And your thing will run when the user submits.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜