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 8032343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:21:31+00:00 2026-06-05T01:21:31+00:00

I have several forms that are created dynamically using PHP. I would like to

  • 0

I have several forms that are created dynamically using PHP. I would like to list all the fields that are mandatory above each form.

t should look like this:

<div class="mandatory_list">Mandatory fields: first name, email</div>

<form>
<label>first name*</label><input type="text" />
<label>last name</label><input type="text" />
<label>email*</label><input type="text" />
<label>comments</label><input type="text" />
</form>

If it would simplify things I can also give all mandatory labels a seperate class. I came this far:

<script>
    var mandatory= ( $("label:contains('*')").text() );
    $('#mandatory_list').html("Mandatory fields: " + mandatory);
</script>

This gives me the following output: “Mandatory fields: first name *email *”. So this would mean I had to replace all asterisks with comma’s. There’s probably a better way to go about this.

  • 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-05T01:21:32+00:00Added an answer on June 5, 2026 at 1:21 am

    I would think it is easier with a class on the mandatory fields, but that is just a preference for the selector:

    :First off, get rid of the extra text in the list and add the class:

    <div class="mandatory_list">Mandatory fields:</div> 
    
    <form> 
    <label class='mandatory'>first name*</label><input type="text" /> 
    <label>last name</label><input type="text" /> 
    <label class='mandatory'>email*</label><input type="text" /> 
    <label>comments</label><input type="text" /> 
    </form>
    

    Now populate the list, removing the last comma as you specified:

    var myList = $('.mandatory_list').text();
    $('.mandatory').each(function() {
        myList += ' ' + $(this).text().replace('*', ',');
    });
    myList = myList.slice(0, myList.length - 1);
    $('.mandatory_list').text(myList);
    

    EDIT: Adapted to your “multiple” forms

    $('form').each(function() {
        var myHeader = $(this).prev('.mandatory_list');
        var myList = myHeader.text();
        $(this).find('.mandatory').each(function() {
            myList += ' ' + $(this).text().replace('*', ',');
        });
        myList = myList.slice(0, myList.length - 1);
        myHeader.text(myList);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that is dynamically created, on this form are several radio
I have a website with several forms that all pass the same set of
I have several forms in my application, and like all forms after the users
I have a page that contains several forms, by submitting each one of them,
I have a page that has several ajax submission forms. Each form has a
I have several label boxes on my design form that all share the naming
I have several radio buttons that are dynamically populated on a form and I
I have an InfoPath form with several fields on, the problem is that one
I have created a windows form application: A presentation library with several windows forms
I have created an html form. it consist of several drop down list for

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.