Results 1 to 3 of 3

Thread: [RESOLVED] Adding Events With Dynamic HTML Control

  1. #1

    Thread Starter
    Fanatic Member aNubies's Avatar
    Join Date
    Aug 2008
    Posts
    558

    Resolved [RESOLVED] Adding Events With Dynamic HTML Control

    Good day,

    I was able to make the adding of html textbox control working perfectly.

    So here's my code for adding textboxes.
    Code:
    var elementCounter = 2;
    
    // NEW BOOK TEXTBOX.
    var newBookTextbox = $(document.createElement('div'))
         .attr("class", "col-md-2");
    
    newBookTextbox.after().html('<input type="text" id="Book' + requestCounter + '" class="form-control width-skills" name="Book' + requestCounter + '" style="font-size:12px" maxlength="2">');
    newBookTextbox.appendTo(multiRequestDiv);
    
    // NEW TITLE TEXTBOX.
    var newTitleTextbox = $(document.createElement('div'))
         .attr("class", "col-md-2");
    
    newTitleTextbox.after().html('<input type="text" id="Title' + requestCounter + '" class="form-control width-skills" name="Title' + requestCounter + '" style="font-size:12px">');
    newTitleTextbox.appendTo(multiRequestDiv);
    As you can see I'm creating two textboxes under the name of "Book" and "Title". Now what I want is to append an OnBlur event upon creating of new instance of textbox "Book" only. So everytime they type on "Book(x)" an alert will be prompted.

    Can anyone help me about this.. Thank you

  2. #2

    Thread Starter
    Fanatic Member aNubies's Avatar
    Join Date
    Aug 2008
    Posts
    558

    Re: Adding Events With Dynamic HTML Control

    I got it

    Code:
    // NEW BOOK TEXTBOX.
    var NewBookTextbox = document.createElement('input');
    
    NewBookTextbox.id = "Book";
    NewBookTextbox.name = "Book";
    NewBookTextbox.className = "form-control";
    NewBookTextbox.style.cssText = "font-size: 12px";
    NewBookTextbox.onblur = function () {
          <!-- Method Here -->
    };
    As you can see I change how I create a dynamic control from using a "$(document.createElement)" to plain, so that I have an access to the function of blur in native way.
    Last edited by aNubies; Jul 15th, 2015 at 05:00 AM.

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: [RESOLVED] Adding Events With Dynamic HTML Control

    If you were able to solve your problem, you should post the code you used to fix it here. That way, if someone is having a similar issue, when they search they don't just find a "I got it" post without a solution.

Posting Permissions

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



Click Here to Expand Forum to Full Width