I used the JavaScript as:
script language="javascript"
function writeResult(text){ document.myform.tDescription.value = text;
}
/script
hence my text field will be:
form="myform" <%=开发者_Go百科 s.text_field 'xyz','abc', :name =>('tDescription'), :size =>50 %> /form
I have to store this text value in the table 'xyz' in column 'abc' but its not working. As ruby on rails by default take the text field name as name="xyz[abc]" , if i m not specifing any name for the text field but becoz of java script the function call I have specify the name as tDescription. Please help how I can store this value in database. If i use input tag instead. What will the controller corresponding code.
give your textfield a unique id
<%= s.text_field 'xyz','abc', :id => "tdescription", :size =>50 %>
now you can have your javascript refer to the id and let rails use name for its uses
either go by classic javascript
getElementById('tdescription')
or my preference use jquery
$('#tdescription')....
精彩评论