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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:48:08+00:00 2026-06-10T23:48:08+00:00

I have some inputs as below: <input type=hidden id=selected_id-1 name=id[] /> <input type=hidden id=selected_id-2

  • 0

I have some inputs as below:

<input type="hidden" id="selected_id-1" name="id[]" />
<input type="hidden" id="selected_id-2" name="id[]" />
<input type="hidden" id="selected_id-3" name="id[]" />
<input type="hidden" id="selected_id-5" name="id[]" />

The list can contain more than just 4 elements.

So, I would like to extract the highest number (in our case = 5) from the ids of elements named “id”.

Pure JavaScript needed.

EDIT: Thank you everybody who answered my question.

  • 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-10T23:48:09+00:00Added an answer on June 10, 2026 at 11:48 pm

    Assuming your elements might not be ordered by id, you’ll have to check them all to find the highest one.

    var inputs = document.getElementsByTagName('input');
    var highest = 0;
    for(var i=0; i<inputs.length; i++) {
        if(inputs[i].name == 'id[]') {
            var current = inputs[i].id.split('-')[1];
            highest = (current > highest) ? current : highest;
        }
    }
    // Now highest contains the highest numeric id
    console.log(highest);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some inputs as below: <input type=hidden id=selected_id-1 name=e_id[] /> <input type=hidden id=selected_id-2
Scenerio: I have some divs populated through foreach loop like below <div id=div1><input type=hidden
I have some hidden inputs like this <input name=exam.normals[1].blahblah ..../> I would like somehow
I have a drop down box and some text input fields below it. Based
I'd like to have some hidden inputs on View A.aspx and pass the values
I can't use EditorFor because my inputs have some other attributes like readonly ,
Currently I have this hidden input in a loop and it works: <input type=hidden
I have a jQuery selector with following syntax: $('input[type=image]').not('.xyzClass').click(function{ //some functionality }); So this
I have some variable: <input type=text id=use /> <div id=app></div> I want if ajax
I have some code below: <!doctype html> <html lang=en> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8

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.