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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:40:20+00:00 2026-05-23T11:40:20+00:00

I have a function that adds a new unordered list item. I’d like to

  • 0

I have a function that adds a new unordered list item. I’d like to set one of the element’s values in the newly created list item to a value that is based on a value in the list item just above the new one.

For instance, if I have something like:

<form id="form" action="">

<ul id="list1" class="listing">

    <li id="input1" class="item">

        <input id="descr1" class="descr" type="text" value="" name="descr1" />
        <input id="group1" class="group" type="text" value="" name="group1" />
        <input id="order1" class="order_field" type="text" value="4" name="order1" />
        <input id="row1" class="checkbox" type="checkbox" value="1" name="select_row1" />

    </li>

    <li id="input2" class="item">

        <input id="descr2" class="descr" type="text" value="" name="descr2" />
        <input id="group2" class="group" type="text" value="" name="group2" />
        <input id="order2" class="order_field" type="text" value="5" name="order2" />
        <input id="row2" class="checkbox" type="checkbox" value="2" name="select_row2" />

    </li>

</ul>

If I run the function that creates a new list item, I want the value in #order2 to be incremented by 1 and then the new list item (that will now have #order3) will be set to 6. For example, after I have created the new list item it would look like this:

    <li id="input3" class="item">

        <input id="descr3" class="descr" type="text" value="" name="descr3" />
        <input id="group3" class="group" type="text" value="" name="group3" />
        <input id="order3" class="order_field" type="text" value="6" name="order3" />
        <input id="row3" class="checkbox" type="checkbox" value="3" name="select_row3" />

    </li>

I need to find a way to get to the last list item and get the value for the class .order_field and then use that value (+1) when I create the new list item. My issue is I’m not sure how to put together the selector for getting to the last list item’s .order_field value.

I hope that makes sense.

Thanks,
Shawn

  • 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-23T11:40:21+00:00Added an answer on May 23, 2026 at 11:40 am

    It’s simply:

    var value = $('#list1 li:last .order_field').val();
    

    You also have to convert the value to a number, which you can do using parseInt or unary +:

    var newValue = parseInt(value, 10) + 1;
    // or
    var newValue = +value + 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically what I have here is a button that adds a new list item
I have a function that adds eventhandlers to control events. Right now I have
I have such function, that adds a grid of droppables: function AddClassroomDrops(grid, weeks, days,
I have this function, that adds 31px to my style bottom on ul. It
I have a javascript function that manipulates the DOM when it is called (adds
I have a function that gets x(a value) and xs(a list) and removes all
I have an unordered list with elements and I want to append an item
I have a form on a page that adds new data to a database
I have a simple webpage that adds & deletes options from a select element
I have a function that adds custom built cameos in a cart. The cart

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.