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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    234
    Thanks
    111
    Thanked 1 Time in 1 Post

    Obtaining input value

    Hi, I am struggling to get the inputted value in order to set it in my header. The code I have is
    Code:
    $("#email-container").on("expand", function(evt) {
            var $this = $(this);
            $this.trigger("collapse");
            var $header = $this.find("#email-header-content");
            $header.html("");
            var $input = $("<input/>").appendTo($header);
    
            $input.on("click", function(evt) {
                evt.stopPropagation();
                return false;
            });
    
        });
    
        $("#email-container").on("collapse", function(evt, ui) {
            var $this = $(this);
            var $headerContent = $("#email-header-content");
    
            var name = $("<input/>").val();
            if (name) {
                $headerContent.html(name);
            }
            else {
                $headerContent.html("Please choose...");
            }
        });
    The input is created in the expand function, and I need to get this inputted value in the collapse function. How would I go about doing this?

    Many thanks

  2. #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,495
    Thanks
    57
    Thanked 637 Times in 632 Posts
    I don't really understand the rest of your code (what does the onclick do?) but if you give your input an ID when you make it, you can get its value later

  3. #3
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    $("#email-container").on("expand", function(evt) {
            var $this = $(this);
            $this.trigger("collapse");
            var $header = $this.find("#email-header-content");
            $header.html("");
            var $input = $("<input/>").appendTo($header);
    
            $input.on("click", function(evt) {
                evt.stopPropagation();
                return false;
            });
    
        });
    
        $("#email-container").on("collapse", function(evt, ui) {
            var $this = $(this);
            var $headerContent = $("#email-header-content");
    
            var name = $("#email-header-content input")val();
            if (name) {
                $headerContent.html(name);
            }
            else {
                $headerContent.html("Please choose...");
            }
        });


 

Posting Permissions

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