0

I have the following input element:

<input type="hidden" id="input_2_204_data" name="input_2_204_data" value>

I need to capture an event when it is changed and value is not empty. I have looked over older SO's questions, however nothing seemed to work.

Here is the latest snippet I have come up with, however it does not work either, and there are no errors in console:

jQuery(document).ready(function(){
    var $sign = jQuery('[id$=input_2_204_data]');   

    $sign.on("change", function(){
        alert('hey');
    });
});

Any help or guidance is much appreciated.

1
  • 2
    There's no event raised when the value of an input is changed programmatically. You should call a function (or trigger an event manually) on the element when needed. Commented Mar 23, 2016 at 9:01

3 Answers 3

2
jQuery(document).ready(function(){
    var $sign = jQuery('#input_2_204_data');   
alert($sign.val())
});
Sign up to request clarification or add additional context in comments.

Comments

0

You have wrong selector to target element, You need to use ID selector # here to target element by id:

var $sign = jQuery('#input_2_204_data');   
$sign.on("change", function(){
    console.log($(this).val());
});

1 Comment

Copied and pasted the snippet, however it does not log the value, netiher logs any error.
0

You have to use the correct selector #input_2_203_data. Using .change() works just fine.

jQuery(document).ready(function(){
  var $sign = jQuery('#input_2_204_data');   

  $sign.change(function() {
    if($sign.val() != '') {
      alert( "Handler for .change() called." );
    }
  });
});

Comments

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.