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 6 of 6
  1. #1
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts

    remove html elements

    New thread, new issue, same jquery as my previous question

    My js created a dropwdown and user input form fields with a click event. The user can add up to three and the "Add" link is removed upon reaching 3 elements.

    Then I have a link to Remove an input in case the user doesnt want to enter more than has been added. The problem now is, we validate the form and at least ONE input must be filled out. SO I need to always have at least one input in the document. My code has a Remove link beside each input ands the user can remove all three.

    I was trying to read about the filter() method and filtering the element based on first:child or something similar.

    Code:
    Code:
      $(document).ready(function(){
       $(".addSMRow").bind("click", function(){
        var $socialForms = $(".socialForms");
        if($(".sm_row").size() < 3){
         $(".moreSocial").append($socialForms.html());
        }/*JME - we can work on the remove link showing up tomorrow*/
        if($(".sm_row").size() > 1){
         $(".remove_row").show()
        }
        if($(".sm_row").size() == 3){
         $(".addSMRow").hide();
        }
        else{
         $(".addSMRow").show();
        }
        return false;
       });
       if($(".sm_row").size() == 3){
        $(".addSMRow").hide();
       }
       $(".remove_row").live("click", function(){
        $(this).parent().remove();
        $(".addSMRow").show();
        return false;
       });
      });
    As you can see, the code says if .sm_row is greater than 1 then show() remove_row

    I need to somehow set an else statement if sm_row is greater than 1, the hide remove_row on the first sm_row only.

    Hope all this made sense. Any help is greatly appreciated.
    Teed

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,789
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    jQuery is a JavaScript framework, therefore it belongs into the frameworks sub forum. Just FYI and for potential future requests.

  • #3
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by VIPStephan View Post
    jQuery is a JavaScript framework, therefore it belongs into the frameworks sub forum. Just FYI and for potential future requests.
    You're right, sorry lol
    Teed

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    One way:

    Code:
    if($(".sm_row").size() > 1){
         $(".remove_row").show();
         $(".remove_row").first().hide();
        }
    This answers your request, but I'm guessing that you really want to hide remove_row for "whichever single input remains" - rather than always the first one?
    Last edited by AndrewGSW; 09-20-2012 at 10:59 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    teedoff (09-21-2012)

  • #5
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by AndrewGSW View Post
    One way:

    Code:
    if($(".sm_row").size() > 1){
         $(".remove_row").show();
         $(".remove_row").first().hide();
        }
    This answers your request, but I'm guessing that you really want to hide remove_row for "whichever single input remains" - rather than always the first one?
    No thats right. The user form starts with one input. The user can add two more, but one will always be available and required according to validation rules. So the Remove text link should only display and work for any inputs added. Not the first constant input on the form.


    I'm not at work now and my remote access is buggy tonight, so I'll check this out when I get in to work in the morning. Thanks!
    Teed

  • #6
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Such a simple solution! Thanks Andrew for the help! Worked great.
    Teed


  •  

    Posting Permissions

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