Re: Javascript with select in partial

RVince
Tue, 01 Sep 2009 01:41:52 -0000

Thank you Hassan -- perhaps I am doing something stupid and not
realising it? It is failing for me in Firefox (latest version) and
Chrome (latest version) I have not tested MSIE. I am running Rails
2.3.2.

I have a partial, /channels/_channelnotesfield.html.erb, with
javascript, as follows:

Notes:
<%= select("channelnotes", "channelnotes",
Channelnote.find
(:all,  :order => ''tstamp DESC'', :limit =>3, :conditions
=>
["deleted=0"]).collect {|p| [ p.note, p.note]}, { :include_blank =>
true , :selected=>0, :value=>""},{:onKeyDown =>
"fnKeyDownHandler
(this, event);", :onKeyUp => "fnKeyUpHandler_A(this, event); return
false;", :onKeyPress => "return fnKeyPressHandler_A(this,
event);",  :onChange => "fnChangeHandler_A(this, event);",
:style =>
"width:350px;",:id=> "channelnotes"}) %>
<%=  observe_field "channelnotes", :url => {:controller
=> :channels, :action => ''notesboxchange'' }, :frequency
=> 1.0, :with
=>  "''channelnotes='' + value" %>

function doReset(){
	document.getElementById("channelnotes").options.selectedIndex = 0;
	document.getElementById("channelnotes").options
[document.getElementById
("channelnotes").options.selectedIndex].value="";
	alert("doReset()"); // so we can see if the javascript is being
executed
}
doReset();


In my ChannelsController I call it with:

def resetchannelnotes
   current_associate.update_attributes(:channelnotes =>
'''',:noteson =>
0)
   render  :partial => ''channelnotesfield''
  end

But the javascript only gets called when the entire page loads. Thank
you -Rvince