开发者

Jquery Not able to fetch changed value of input field

I am trying to fetch the changed input filed value using jquery which is getting changed javascript event of drop down select. I simply am not getting where exactly the things are getting wrong. It is something related to dom tree refresh (.live)? Any help/suggestions would be great. Thanks.

/* adding the value to user_val input field id in javascript onload function based on drop down select event*/
document.getElementById('user_val').Value = "abcd";


/* then trying to get value which changed  */
$(document).ready(function() {
          $("#sub开发者_JAVA技巧mits").click(function() {        
              alert($("#user_val").val());
});


You haven't closed your click event handler function. Change it to this:

$(document).ready(function() {
          $("#submits").click(function() {        
              alert($("#user_val").val());
          });
});

And change Value to value (note the lowercase "v"), and then it should work fine.


Two errors you got there:

  1. You should use document.getElementById('user_val').value = "abcd"; and not document.getElementById('user_val').Value = "abcd"; (lower case value, not Value).

  2. You should also close the ready event after your click event.

  3. Here is the complete working solution:

    /* adding the value to user_val input field id in javascript onload function based on drop down select event*/
    document.getElementById('user_val').value = "abcd";
    
    /* then trying to get value which changed  */
    $(document).ready(function() {
        $("#submits").click(function() {
            alert($("#user_val").val());
        });
    });
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜