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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:43:32+00:00 2026-05-11T05:43:32+00:00

To teach myself Javascript, I’m trying to make a web page that gives users

  • 0

To teach myself Javascript, I’m trying to make a web page that gives users a list of items (e.g. foods), asks them to sort these foods from favorite to least favorite, and submit the data when they’re done. Using jQuery sortables seems like a good way to do this. However, I’m not sure how the data submission should happen.

Here’s what I’m thinking. Each of these food items would be in a div like this:

<div id='sortable'>     <div id='1' class='foods'>Pizza</div>     <div id='2' class='foods'>Sushi</div>     <div id='3' class='foods'>Taco</div> </div> 

When the user clicks a ‘submit’ button, I want the order of these items to be determined, and for this ordering to be sent back to the server (by the way, I’m using Django on the server side). It seems I can determine the order of the items with a function like this:

function getOrder() {     var foods = $('.foods');     var ids = [];      for(var x=0; x<foods.length; x++)     {         ids.push(foods[x].id);     }     return ids; } 

However, I’m stuck on a couple of things:

  • Where in my code would I call this function? I’m thinking it would be an onclick action when the user presses the submit button, but I’m not sure where the data the function returns would get passed.
  • What format would be the most appropriate for sending this ordering to the server (e.g JSON)?

(I know this is a really basic question, but I have never made a web page with JavaScript before, so this area of programming is all new to me.)

  • 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. 2026-05-11T05:43:32+00:00Added an answer on May 11, 2026 at 5:43 am

    A more semantically relevant way of doing a list is by using an actual <ul> element.

    So if you had something like this:

    <ul id='foods'> <li id='food_1'>Pizza</li> <li id='food_2'>Sushi</li> <li id='food_3'>Taco</li> </ul> <a href='javascript:saveFoods();'>Save Order</a> 

    The following jQuery code would be appropiate:

    function saveFoods(id) {     var data = $('#foods').sortable('serialize');     var action = '/django/view/';     $.post(action, data, function(json, status) {         if(status == 'success' && json.status == 'success') {             alert('Saved order of the foods!');         } else {             alert('Unable to complete the request.');         }     }, 'json'); } 

    According to the jQuery docs on sortable, when you use serialize the elements of a sortable it requires their IDs to be in a setname_number format. So by having your list as food_1, food_2, etc. jQuery recognizes that the ID of Pizza is 1 and its set is food. The data variable in saveFoods will then contain something like food[]=1&food[]=2&food[]=3 that you can process in your Django app.

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not how you want to use your WCF… May 11, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer Maybe you can find something looking through the documentation of… May 11, 2026 at 5:42 pm
  • Editorial Team
    Editorial Team added an answer Depends on the type of caching you are talking about.… May 11, 2026 at 5:42 pm

Related Questions

To teach myself Javascript, I'm trying to make a web page that gives users
I am creating a Silverlight 2 user interface to a remote instrument. There are
I decided to teach myself assembly language. I have realized that my program will
I'm basically trying to teach myself how to code and I want to follow
I'm trying to teach myself Ruby's Treetop grammar generator. I am finding that not

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.