text_field and :onchange

Hi all,

I have this text_field that needs to be filled out before a form can be
submitted. To do this I added an :onchange attribute that basically
checks to see if the value of the field is blank, if it is then the
submit button on the form gets hidden, else it is shown. The idea also
being that if the user enters a value, the button should be shown, but
if that value is deleted, the button should be removed from the page as
well.

Here is my code:

<%= text_field 'param', 'category',
  {:onchange => 'document.getElementById(\'param_category\').value != ""
?
     document.getElementById(\'go_button_div\').style.display =
\'inline\' :
     document.getElementById(\'go_button_div\').style.display =
\'none\';'} %>

It works, but not exactly as desired. I would like this to show the
button even if a single character is entered and then hidden if it is
deleted. As it is now, the button is only displayed when the text_field
is not on focus, which for my purposes does work but I feel this could
be confusing and irritating to the end user.

Am I mistaken in thinking that the using :onchange should give me this
effect, or is there an error in my code? It almost seems like :onchange
and :onfocus are working in the same manner in this example.

Thanks,

-S

:onkeyup does what I want. wouldn't you know no more than five minutes
after I post this a light goes on and I figure it out.

-S

try to go unobstrusive