Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9318119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:02:11+00:00 2026-06-19T03:02:11+00:00

User have some list (exactly list, but not the point). User can add to

  • 0

User have some list (exactly list, but not the point). User can add to list some other unique elements – strings. Form, allowing to submit new element, is hidden. To add new one user press button “Show Add Fruit Form”, form appears, getting string, and if string unique, push it to string, if not – alert message.

Problem is:

  • At first adding all works fine.
  • At second and next adding if:
    • string unique – string push to array and alert message about string not unique
    • string not unique – multiple one by one alerts message about string not unique

html:

<div id="plus_tab">Show Add Fruit Form</div>

<div id="div_form" class="hidden">
    <form id="my_form" >
        <input type="text" name="value1"/>
        <input type="submit" value="Add fruit"/>
    </form>
</div>

<div id="result">
    result
</div>

js:

var fruits = ['apple', 'strawberries']

$('#plus_tab').click(function(){
    $("#div_form").removeClass('hidden').addClass('visible')
    $("#my_form").submit(function(event){
        event.preventDefault()
        new_fruit  = $(this).find('input[name="value1"]').val()
        if ($.inArray(new_fruit, fruits)==-1 ){
            fruits.push(new_fruit);
            $('#result').empty().append(fruits);
            $("#div_form").removeClass('visible').addClass('hidden');
        }else {
            alert('Name '+new_fruit+' exist, choose other')
        }
    })
})

css:

.hidden {
    display: none;
}
.visible {
    display: block;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:02:12+00:00Added an answer on June 19, 2026 at 3:02 am

    With your code, you will add one extra submit handler each time you click on #plus_tab

    The submit handler should be bound only once :

    $("#my_form").submit(function(event){
        event.preventDefault()
        new_fruit  = $(this).find('input[name="value1"]').val()
        if ($.inArray(new_fruit, fruits)==-1 ){
            fruits.push(new_fruit);
            $('#result').empty().append(fruits);
            $("#div_form").removeClass('visible').addClass('hidden');
        }else {
            alert('Name '+new_fruit+' exist, choose other')
        }
    })
    
    $('#plus_tab').click(function(){
        $("#div_form").removeClass('hidden').addClass('visible');
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not too familiar with cmd or anything, but I have done some research
I have some user-submitted variables that I want to display in a different part
I have some activity were user goes through it and finally send the selected
I have some polygons on a map and when the user double clicks on
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have some Mongoose Models with geospacial indexes: var User = new Schema({ name
I have some items that I'd like the user to be able to filter
I have some code where, if a user has referred X number of people,
I have some java classes like, Class User { String email; String name; String
I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.