views:

62

answers:

1

hi

i am using remote_function call

onchange before calling remote_function i want to check the condition

iam using code written below

<%= select_tag 'name', options_for_select(search.collect{ |v| [v.name]})+ "-Add Name-", :onchange => remote_function(:url => {:controller => :name, :action => :create_name}) %>

here i want to check if (escape(value) == -1) then call remote_function

A: 

Why do you want do the check here ? You may do check inside yoiur remote_function for example

if (escape(value) == -1){
  //do something
}

or

if (escape(value) == -1){
  //do something
}else{
  //do nothing or do something else
}

edits

example helper

def my_remote_function(var)
  s = ""
  if (var == "false")
    s = "alert('java')"
  end 
  s
end

 <%= select_tag "people", "<option>David</option><option>Bruse</option>", :onchange=>my_remote_function("true")
Bohdan Pohorilets
i tried using if condition inside remote function its not working..can u please show me how to use if conditon in this code,:onchange => remote_function(:url => {:controller => :name, :action => :create_name}) %>
nirmal
:onchange accepts string as an argument so you may write some helper method which accepts "value" as a param and returns some string or nothing or you may write ruby core inside string
Bohdan Pohorilets
added example of helper
Bohdan Pohorilets