views:

189

answers:

1

I have an html.erb file which includes the following

<%= submit_tag "Locate", :disabled => true %>

I also have <%= text_field_tag 'locationPOS', "", :disabled => true %> which has its value updated when the user click on the google map present on the page (from a separate javascript file) by locpos.value = place.address;

I would like to enable the submit_tag only when there is text within the 'locationPOS' text_field_tag.

Any suggestions please?

+1  A: 

in your view:

<%=text_field_tag 'locationPOS', "", :disabled => true, 
:onchange => "check_value(this.value);" %>

and

<%= submit_tag "Locate", :disabled => true, :id => "my_submit_button" %>

Add javascript function to your view similar to this:

function check_value(val)
{
  if(val.length > 0)
  {
    document.getElementById("my_submit_button").disabled=false;
  }
}

I am sure some debugging of above code will be necessary. :)

LymanZerga
Thanks a lot! this helped me notice that all i needed to add was :id =>"my_submit_button" after all in my previous code which made it work like a charm. thanks!!
Erika