Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Get values of previously generated input fields

    Hello there,

    I've got a simple question, since I'm not yet that good in understanding javascript.

    It's not possible to get an input value with jQuery, when you've previously generated that input field (with value), in another function?

    So schematicaly:

    function 1: generate input fields with values
    function 2: get values of those input fields

    I know the syntax of getting the values of input fields, but I can only get values of static input fields.


    If it however IS possible, can someone explain me how to do this?
    Thank you.

  • #2
    New Coder
    Join Date
    Apr 2010
    Location
    Norfolk, England
    Posts
    63
    Thanks
    1
    Thanked 14 Times in 14 Posts
    Hi fishbaitfood

    It depends how you are dynamically creating the elements.

    If you are adding them to the DOM properly, then normal value retreival methods should be fine (treat them as static entries)

    However if you are just adding the HTML, via something like .innerHTML, then, well, don't
    //Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks thesam101,

    I'm using a toggle button to add or remove a table row with the containing input field and value.
    I'm adding the row using .after()

    I'm able to get those values within the same function, but not in a new click function outside the toggle function.


    Update: I "hardcoded" the table row into my html document, and then I'm able to get the input value.
    However, if I add this row with jQuery .after(), I cannot get that value.

    How do I solve this?
    Last edited by fishbaitfood; 11-03-2011 at 11:16 PM.

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,956
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Replace your click function with .live() - so instead of:

    Code:
    $('#myelement').click(function(){
    
       ...do things...
    
    });
    make it

    Code:
    $('#myelement').live('click',function(){
    
       ...do things...
    
    });

  • Users who have thanked SB65 for this post:

    fishbaitfood (11-04-2011)

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    Replace your click function with .live() - so instead of:

    Code:
    $('#myelement').click(function(){
    
       ...do things...
    
    });
    make it

    Code:
    $('#myelement').live('click',function(){
    
       ...do things...
    
    });
    Wow, I can't believe this just works perfectly!
    Could you explain to me why click doesn't work this way?

    I also tried .live() with toggle, but that doesn't seem to work?

    Thanks SB65!

  • #6
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,956
    Thanks
    9
    Thanked 727 Times in 721 Posts
    $(selector.click() will attach an event handler to all current elements which match selector, whereas .live() allows you to extend this to elements which match now or in the future.

    .live works with events - so click, mouseover, mouseout etc will work, but toggle won't because it isn't an event.

  • Users who have thanked SB65 for this post:

    fishbaitfood (11-04-2011)

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks for the help and info SB65!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •