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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:15:42+00:00 2026-05-26T00:15:42+00:00

I have a PHP page with a form like this: <form class=form3> <label class=form3><input

  • 0

I have a PHP page with a form like this:

<form class="form3">
<label class="form3"><input type="checkbox"> Item-1</label>
<label class="form3"><input type="checkbox"> Item-2</label>
<label class="form3"><input type="checkbox"> Item-3</label>
<label class="form3"><input type="checkbox"> Item-4</label>
<label class="form3"><input type="checkbox"> Item-5</label>
</form>

I have javascript variables set like this:

var checked = ["", "yes", "", "yes", ""];

Now when the page is loaded, I want to check if the the checked value is “yes” then I want to put those input items first in teh list and the remaining ones later, like this:

<form class="form3">
<label class="form3"><input type="checkbox" checked="checked"> Item-2</label>
<label class="form3"><input type="checkbox" checked="checked"> Item-4</label>
<label class="form3"><input type="checkbox"> Item-1</label>
<label class="form3"><input type="checkbox"> Item-3</label>
<label class="form3"><input type="checkbox"> Item-5</label>
</form>

I assume, jQuery would be the way to do it.
which means, I will need to loop through the form fields (which I am not sure how) and inside the loop check if the corresponding variable is blank or ‘yes’, and if yes, print that form field. Then again go through the same loop and print all fields where corresponding variable is blank.

Hope the logic is correct.

I am able to loop through the form elements like this:

$.each($('.form3'),function(i,e){
    if(checked[i] == "")
        {
            e.appendTo($('.form3'));
        }
});

BUT
obviously, the appendTo line gives me error:

Uncaught TypeError: Object #<HTMLLabelElement> has no method 'appendTo'

So, now I would need to know how to pick each one of the rows and reorder them while looping.

Thanks

  • 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-05-26T00:15:43+00:00Added an answer on May 26, 2026 at 12:15 am

    Try this instead:

    $('.form3').each(function(i,e) {
    
        if(checked[i] == "") {
    
            $(this).find('input[type=checkbox]').attr('checked', true);
            $(this).appendTo($('form'));
    
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page like this: <form class=ajax method=post action=add_item.php> [text input] [submit button]
I have a form like this: <form class=category_form id=category_form method=post> <p class=ui-widget> <label for=birds>Birds:
so I have a simple login page like this: <fieldset> <legend>Verification</legend> <form method=post action=authentication.php>
i have a controller page like this: class UsersController extends AppController { var $helpers
I have a page with a form like so: <form method=POST action=scripts/save-settings2.php> <div id=posts>
I have a PHP page that queries a DB to populate a form for
I have a form page in PHP that reads a DBF, and conditionally converts
I have a simple html form. On php page. A simple list is placed
I have a php page and i have some javascript code to have a
I have a form on a page that sends data to php file via

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.