Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2012, 04:23 PM   PM User | #1
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
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
teedoff is offline   Reply With Quote
Old 09-20-2012, 04:43 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,585
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
jQuery is a JavaScript framework, therefore it belongs into the frameworks sub forum. Just FYI and for potential future requests.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-20-2012, 08:57 PM   PM User | #3
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
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
teedoff is offline   Reply With Quote
Old 09-20-2012, 10:56 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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?
__________________
"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

Last edited by AndrewGSW; 09-20-2012 at 10:59 PM..
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
teedoff (09-21-2012)
Old 09-21-2012, 02:56 AM   PM User | #5
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
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
teedoff is offline   Reply With Quote
Old 09-21-2012, 03:56 PM   PM User | #6
teedoff
Senior Coder

 
Join Date: Aug 2010
Location: High Point, NC
Posts: 3,325
Thanks: 5
Thanked 363 Times in 360 Posts
teedoff is on a distinguished road
Such a simple solution! Thanks Andrew for the help! Worked great.
__________________
Teed
teedoff is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:35 PM.


Advertisement
Log in to turn off these ads.