简体   繁体   中英

Rails Javascript Empty string passed to getElementById()

I have a Rails 3.2 app. The following javascript was working fine. Now, it's getting 'Empty string passed to getElementById().' Also getting Use of getPreventDefault() is deprecated. Use defaultPrevented instead. Use of getPreventDefault() is deprecated. Use defaultPrevented instead. in the console.

I'm not sure what changed?

 $('#costproject_rebudget_funds').change ->
    alert "hey"
    checkbox = document.getElementById('costproject_rebudget_funds')
    if checkbox.checked
      $("#costproject_new").attr('checked', false)
      $("#costproject_rebudget").attr('checked', false)
      $("#rebudgetamount").show()
    else
      $("#rebudgetamount").hide()
      $("#costproject_rebudget_amount").val('')

I added the alert "hey" for troubleshooting. It is getting triggered.

You use jquery everywhere else except right at the checkbox = document.getElementById('costproject_rebudget_funds') line. Why not get the element using jquery? checkbox = $('#costproject_rebudget_funds').get(0) perhaps? Here is a post possibly talking about some of the issues you are having: How to do this using jQuery - document.getElementById("selectlist").value

Particularly note the second answer not the picked one.

For your deprecation error i'm unsure because you aren't showing the preventDefault code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM