0

I've following DOM structure

<form name="address_form" method="post">
   <input type="hidden" name="action" value="update_address_details">
   <input type="hidden" name="latitude" value="52.367659">
   <input type="hidden" name="longitude" value="-0.409539">
   <input type="hidden" name="map_zoom_point"  value="14">
   <input type="text" name="address" value="" value="brington"> //visible element
   <input type="submit" name="submit" value="Update"/>  //visible element
</form>   

I'm showing above form to user with some default input data available in DB below this form I'm showing an OpenLayers map based on latitude,longitude and map_zoom_point.

If user move marker image on OpenLayers map then hidden fields in the above form will be automatically updated, I want capture this change using jQuery. If I use below code,

$('form[name=address_form] input').on('change keypress',function() { 
    console.log('something');
 });

then console.log only prints if user modifies text in address field otherwise it won't print the log message even hidden fields get changed.

Mahesh.D
  • 1,691
  • 2
  • 23
  • 49
  • 1
    What exactly is your question? – Derek Henderson Jun 03 '13 at 13:03
  • 2
    possible duplicate of [Jquery - Detect value change on hidden input field](http://stackoverflow.com/questions/6533087/jquery-detect-value-change-on-hidden-input-field) – jbabey Jun 03 '13 at 13:04
  • I think you need to associate the change event to the specific element inside the dom than the form itself.as these changes arent making any changes to the form tag. – dreamweiver Jun 03 '13 at 13:04
  • @dreamweiver: He is. The selector he's using to bind the `change` and `keypress` events is selecting `input` tags. The issue at hand is that `hidden` form elements don't fire those events. – David Jun 03 '13 at 13:05
  • 1
    The fields are being modified programatically, so the `change` event doesn't fire. You need to trigger it manually when a marker is moved. Presumably this will be covered in the documentation – billyonecan Jun 03 '13 at 13:06
  • @billyonecan: your right – Mahesh.D Jun 03 '13 at 13:07
  • I had this same problem with the keypress/change event, and started writing a jquery plugin to solve it. Should mostly work, you may have to tweak it tho. [It is here](https://github.com/etaubman/jquery-typeintent) – Ethan Jun 03 '13 at 13:09

0 Answers0