Disable submit button in coffeescript

I have some date validation that I am doing that works well. In addition to displaying an error message when there is an invalid date range I would like to disable/enable the submit button. Here is my coffeescript...

jQuery ->
  to_date = null
  from_date = null
  $("#to_date, #from_date").bind "change", ->
    from_date = new Date($('#from_date').val())
    to_date = new Date($('#to_date').val())
    if from_date > to_date
      $("#date_error").text("Error! Not a valid date range")
      $("#submit_button").attr("disabled", true)

...and my html when I do view/source...

  <div id="submit_button">
    <input name="commit" type="submit" value="Create Orientation" />

I know my JS is loading cuz my error message is being displayed, no button disabled. Ideas?


You can't disable a div. You've to disable the actual input. So just do this:

$("#submit_button input").attr("disabled", true)

You can use .preventDefault();

I didn't try with your code, but you can test this:

  $('#submit_button input').click (e) ->

Need Your Help

why is document.getElementsByName("name") is not returning any values?

javascript internet-explorer-8

I am creating an html element and assigning id and name values programmatically and later when i am trying to access those elements by name it is not returning any value

Wordpress - WP_Query Multiple OrderBy Meta_Key

wordpress arguments sql-order-by wp-query meta-key

I want to output a list of guides, where each guide has votes and rating. So I want to sort the guide list by rating and votes.