Observer_field

Hi
I have the field Category, SubCategory, and ProductType in select
boxes
When a category is selected corresponding subcategory is selected and
its corresponding product type is to be selected…But i have when a
category selected subcategory selected and its produt type selecetd for
first time…But after observerfield update div as follow my product type
not updated code as below
Category
<%= select( “sd_ticket”, “service_desk_category_id”,
ServiceDeskCategory.find(:all).collect {|p| [ p.name, p.id ] }) %>

Subcategory

<%= select( "sd_ticket", "service_desk_sub_category_id", ServiceDeskSubCategory.find(:all, :conditions => ["service_desk_category_id =?", 1] ).collect {|p| [ p.name, p.id ] }) %>

<%= observe_field(“sd_ticket_service_desk_category_id”,
:update => “sub_category_container”,
:url => { :controller => :popup, :action =>
:prepare_sub_category },
:method => “post”,
:with => “‘category_id=’+value”) %>

Product type

<%= select( "sd_ticket", "service_desk_product_type_id", ServiceDeskProductType.find(:all, :conditions => ["service_desk_sub_category_id =?", 1] ).collect {|p| [ p.name, p.id ] }) %>

<%= observe_field(“sd_ticket_service_desk_sub_category_id”,
:update => “product_type_container”,
:url => { :controller => :popup, :action =>
:prepare_product_type },
:method => “post”,
:with => “‘sub_category_id=’+value”) %>

In the controller with rjsthe div is replaced with same code
Please help
Sijo

Hi
I could not solve this yet…When I click on the sub category select
box corresponding product types are listed on Product type select
box…But when I click on the ategory select box corresponding
Subcategory are selected in the subcategory select boxe But then its
product types are not filled in ProductType select box…How can I solve
this…Please help

Sijo

On 25 Jun 2008, at 06:23, Sijo Kg wrote:

Hi
I could not solve this yet…When I click on the sub category select
box corresponding product types are listed on Product type select
box…But when I click on the ategory select box corresponding
Subcategory are selected in the subcategory select boxe But then its
product types are not filled in ProductType select box…How can I
solve
this…Please help

It’s probably to do with the observer still observing the ‘old’ select
box that you have since replaced. You can probably make your life
easier by using an onselect rather than the whole observe_field thing.

Fred

On 25 Jun 2008, at 10:02, Sijo Kg wrote:

Hi
Thanks for your eply…Could you please explain little bit more.I did
not understand .

I’m speculating that the observe_field is still observing the replaced
select, not it’s replacement and saying that you could use an
onchange instead of an observer

Fred

Hi
Thanks for your eply…Could you please explain little bit more.I did
not understand .

Sijo

Hi
I am solving as you said.Only one more thing to solve.I have two js
function like

function set_sub_category(val)
{
new Ajax.Updater(‘sub_category_container’,
‘/popup/prepare_sub_category’, {
parameters: { category_id: val},
onSuccess: javascript:set_product_type(5);
});
}

function set_product_type(val)
{
alert(val);
new Ajax.Updater(‘product_type_container’,
‘/popup/prepare_product_type’, {
parameters: { sub_category_id: val}
});
}

Here how can I call set_product_type function onSuccess of
set_sub_category?Also how can i return value from
/popup/prepare_sub_category action to set_sub_category?

Thanks in advance
Sijo

Hi
Thanks Its working…May I ask you one more?.Here I am just blindly
passing 5 to set_product_type…Actually it is the
service_desk_sub_category_id…How can I access this from response?

Sijo

On Jun 25, 1:13 pm, Sijo Kg [email protected] wrote:

Hi
Thanks Its working…May I ask you one more?.Here I am just blindly
passing 5 to set_product_type…Actually it is the
service_desk_sub_category_id…How can I access this from response?

$F(‘service_desk_sub_category_id’) assuming you mean the value of the
input item with that id

Fred

On 25 Jun 2008, at 12:52, Sijo Kg wrote:

   onSuccess: javascript:set_product_type(5);
  });

}
That’s not syntactically correct: the parameter to onSuccess should be
a function , eg onSuccess: function(response){set_product_type(5)}
The response rendered by the server is available as
response.responseText.

Fred

Here when I gave
onSuccess: function(response){javascript:alert(response.responseText)

I get
<select id=“sd_ticket_service_desk_sub_category_id”
name=“sd_ticket[service_desk_sub_category_id]”
onchange=“javascript:set_product_type(this.value);”

Category4-1 Category4-2 Category4-3

How can I access the value 9 (which is what I need in this case)…That
solves my problem

Thanks in advance
Sijo

On 25 Jun 2008, at 13:31, Sijo Kg wrote:

Here when I gave
onSuccess: function(response){javascript:alert(response.responseText)

stop sticking in those javascript: things, theu’re completely
superfluous at the best of times and syntatically invalid in the one
above. Also, why bother messing around with the ajax response when you
can just look at the form element?
($F(‘sd_ticket_service_desk_sub_category_id’))

Fred

Hi Fred
Thanks a lot for helping me to solve this problem…For the last two
days I was struggling with this …Thanks again

Sijo