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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:38:35+00:00 2026-05-15T11:38:35+00:00

I need to get the first element from a form, could be a select,

  • 0

I need to get the first element from a form, could be a select, text, radio etc. I can get all the elements using the following:

$('myformcontainer').getElement('form').getElements('select,input[type=text]');

And this returns all my form elements, however the problem is that the items are organised by tag type (in this example; select items would be before any text field, even if the text field is first).

How can I sort this array so that the first item in the form is first? Or, a better way of getting them?

Btw, I’ve tried getFirst – it always returns null.

  • 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-15T11:38:35+00:00Added an answer on May 15, 2026 at 11:38 am

    http://www.jsfiddle.net/EtGKE/

    on markup of:

    <form id="myform">
        <input type="text" value="bar" name="bar" />
        <select name="sel">
            <option>foo</option>
        </select>
        <input type="text" value="foo" name="foo" />
        <input type="password" />
    </form>
    

    with code:

    var allEls = document.id('myform').getChildren().filter(function(el) {
        var tag = el.get("tag"), type = el.get("type");
        return tag == "select" || (tag == "input" && type == "text");
    });
    

    this will get you the natural order of the items as an array, use allElls[0] to reference the first one.

    incidentally, this bug has been fixed in mootools 1.3 where the new slick selector engine will not break the order so your code will actually be working as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get only the first matched elements from my tree (if element
I am building a report from information received from a muti-select form element in
How do you get the first element from an array like this: var ary
I need to get the first and last dimension of an numpy.ndarray of arbitrary
I have the following HTML and I need to get the first div parent
Normally, we get first value that way: $(#color option:first).val() But I need something like
I need to get the value of the first checkbox which is checked and
I need a regular expression to basically get the first part of a string,
I need get all items these have no categories int? categoryId = null; var
I have linq request. I need get item.Title in select. how do this? var

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.