2

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 Answer 1

2

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. :)

Sign up to request clarification or add additional context in comments.

1 Comment

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!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.