开发者

How to deal with <%= text_field %> in ruby on rails when javascript is used

开发者 https://www.devze.com 2023-02-19 22:11 出处:网络
I used the JavaScript as: script language=\"javascript\" function writeResult(text){ document.myform.tDescription.value = text;

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')....
0

精彩评论

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

关注公众号