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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:23:17+00:00 2026-05-28T20:23:17+00:00

i have 5 links that gets created in a loop ($.each): $.each(data, function(index, element)

  • 0

i have 5 links that gets created in a loop ($.each):

$.each(data, function(index, element) {
name = element.name;
id = element.id;
    $('<a href="#" id="'+id+'" onClick="submitNotification('+id+');">'+name+'</a>')

});

in my case this will create 5 links:

<a href="#" id="1" >name1</a>
<a href="#" id="2" >name2</a>
<a href="#" id="3" >name3</a>
<a href="#" id="4" >name4</a>
<a href="#" id="5" >name5</a>

and

function submitNotification(cdata){
alert('you selected '+cdata->name+' on '+place+'place');

         $.ajax({ 
    type: 'POST', 
    url: 'http://www.example.com/test.php', 
    data: cdata,
    dataType:'json',
    success: function (data) {
    ...
    }

});
}

what i want is when i click on any link to get the alert: you selected name2 on 1 place. Then if i click another link to get the same alert but with the place var incremented by one.

In other words Each time i click on a link i get place starting at 1 and increment 1 until it gets to 5

then send data to a ajax post.

Now, there are 2 things i have dificulty doing:

1. placing id and name inside an javascript object so i they both can be available to send to the ajax post
2. how do i do the increment so that no matter on what link i click first the countwill start from 1. 

any ideas? knowing this will help me a lot.

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-28T20:23:18+00:00Added an answer on May 28, 2026 at 8:23 pm

    Declare the place counter and data container outside the function:

    var place = 0, postData = [];
    
    function submitNotification(cdata){
      place++;
      alert('you selected '+cdata->name+' on '+place+'place');
    
      postData.push(cdata);
    
      if (place == 5) {
    
             $.ajax({ 
        type: 'POST', 
        url: 'http://www.example.com/test.php', 
        data: { places: postData },
        dataType:'json',
        success: function (data) {
            ...
          }
        });
    
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this situation: <a href=# onClick=submitNotification(1);>click1</a> <a href=# onClick=submitNotification(2);>click2</a> <a href=# onClick=submitNotification(3);>click3</a> function
Change all links that have an image in it to: javascript(alert(thehref)); eg. <a href=/galleries/anna-leah-111827/image01.html><img
I currently have links w/ class=ajax that I want to retrieve the element with
I have an update panel on my page with some links that have onClick
I have created a working DropDownListFor which gets the data from a selectlist which
I have 5 links that are on the same form but I would like
I have links like these that I want to change: mypage.com?page=missions&id=5 mypage.com?page=hello I tried
I have a few links that should all open in the same window or
On this page there is a list of footer links that have a little
Is there a coding standard for HTML? Please suggest links that have the coding

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.