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

  • Home
  • SEARCH
  • 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 7955201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:39:32+00:00 2026-06-04T03:39:32+00:00

i have a page with a link , when use clicks the link a

  • 0

i have a page with a link , when use clicks the link a new select tag will be appeared , then when the user submit the form i want to ensure that the user select an option for each select tag

you can go to the last jquery function , but i put some codes of creating the select tags

html

<div class="container" id="addCell">
    <form id="acForm"method="POST" action="<?php echo URL; ?>Cell/addCell">
        <ul>
            <li>
                <p>
                    <label>Name</label>
                    <input type="text" name="name"class="longInput1"/>
                <p>
                <p>
                    <label>City</label>
                    <select id="countrySelector" name="city">
                    </select>
                </p>
            </li>
            <li id="intersectionCells">
                <p>
                    <label>Inserted cells</label>
                    <a href="#" class="smallLink" id="acaclink">new</a>
                </p>
            </li>
            <li>
                <input type="submit" class="button1" value="save"/>
            </li>
        </ul>
    </form>
</div>

jquery

$("#addCell").ready(function(){
    $("#addCell").on('click',"#acaclink",function(){
        var me = this;
        var cityName = $("#countrySelector").val();
        $.getJSON("http://localhost/Mar7ba/Cell/getCellsInCity/"+cityName+"/TRUE",function(data){
            var options = '';
            options+="<option>Select Cell</option>";
            for(var i=0;i<data.length;i++){
                options += "<option>"+data[i]+"</option>";
            }
            $(me).closest('li').append('<p>\n\
            <label>Select Cell</label>\n\
            <select name="acSelect[]">\n\
             '+options+'\n\
</select>\n\
<a href="#" class="removeA">delete</a>\n\
<span class="errorMessage"></span>\n\
</p>');
        });
    });
});
$("#addCell").ready(function(){
    $("#addCell").on('click',".removeA",function (){
        $(this).closest('p').remove();
    });
});
$("#addCell").ready(function (){
    $("#countrySelector").change(function (){
        var cityName = $("#countrySelector").val();
        $.getJSON("http://localhost/Mar7ba/Cell/getCellsInCity/"+cityName+"/TRUE",function(data){
            var options = '';
            options+="<option>Select Cell</option>";
            for(var i=0;i<data.length;i++){
                options += "<option>"+data[i]+"</option>";
            }
            $("#intersectionCells select").html(options);
        });
    });
});

and this is the form validation

$("#addCell").ready(function (){
    $("#acForm").on('submit',function (){
        var errorCount = 0;
        $('span.errorMessage').text('');
        $('#intersectionCells select').each(function(){
            var $this = $(this);
            if($this.val() === 'Select Cell'){
                var error = 'Please select a cell' ; // take the input field from label
                $this.next('span').text(error);
                errorCount = errorCount + 1;   
            }
        });
        if(errorCount==0){
            $(this)[0].submit(); // submit form if no error
        }
    });
});

but the spam doesn’t appear as i want

  • 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-04T03:39:34+00:00Added an answer on June 4, 2026 at 3:39 am

    See: http://jsfiddle.net/ujrNu/

    After this

    if(errorCount==0){
                $(this)[0].submit(); // submit form if no error
            }
    

    you should add:

    else{
       return false;
    }
    

    otherwise your form will get posted anyway.

    The second problem is this line:

    $this.next('span').text(error);
    

    next returns the NEXT sibling, not the next sibling that is a span. If the next sibling is NOT a span, it will return null. In your case, the next sibling isn’t a span, it’s an A tag. So you want this:

    $this.siblings('span :first').text(error);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have html page with a link when user clicked that link a new
I have a page that contains a link like this: <a href= onclick=add()>new user
I have a page in MVC3, with a link (Ajax.ActionLink). When user clicks it,
I have an link in HTML and I use Page Object pattern to write
hi i have a page contains a link , when user click the link
i have a page , with a link , if the user click the
Is it possible to block a page when a user clicks on a link
I have a page with a link in it , when pressing the link
i have a page on which i am using h:link like <h:link outcome=countryPages_View.xhtml> <img
I have a page in which i have provided a link clicking on which

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.