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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:56:55+00:00 2026-06-07T03:56:55+00:00

I am doing a rating application in php,here I want to write a for

  • 0

I am doing a rating application in php,here I want to write a for loop inside a jQuery ajax function call.I dont know how the correct syntax.

PHP code I used is

for(i=1;i<=4;i++)
{
<div class="like">
<a href="#" class="like" id="1" name="up"><img src="images/likebig.png"></a>
<a href="#" class="like" id="1" name="down"><img src="images/dislike.png"></a>

 <form>
 <input type="hidden" id="<?php echo $i; ?>" value="<?php echo $_SESSION['r_id'][$i]?>">
 </form>
}
</div>

The above code gives four results.Here I want to get the value ($_SESSION[‘r_id’][$i]) of each result on the click of their corresponding click

The jQuery function I used is

<script type="text/javascript">

    $(document).ready(function()
    {
    $(".like").click(function(e)
    {
    e.preventDefault();
    var id=$(this).attr("id");
    var name=$(this).attr("name");
    var fname = $("#fname").val();
    var lname = $("#lname").val();
    var email = $("#email").val();
    for(var i=1;i<=4;i++)
    {
    var rel[i] = $("#i").val();
    }
    var dataString = 'id='+ id + '&name='+ name + '&fname='+ fname + '&lname='+ lname + '&email='+ email;
     $.ajax
      ({
      type: "POST",
      url: "rate.php",
      data: dataString,
      cache: false,
      });
     });
    });
</script>
  • 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-07T03:56:57+00:00Added an answer on June 7, 2026 at 3:56 am

    change this

    var rel[i] = $("#i").val();
    

    to:

    var rel[i] = $("#" + i).val();
    

    alternatively you can use .serialize() method:

    The .serialize() method creates a text string in standard URL-encoded notation. It operates on a jQuery object representing a set of form elements. The form elements can be of several types:

    $.ajax({
       type: "POST",
       url: "rate.php",
       data: $('form').serialize(),
       cache: false,
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following
Doing some jquery animation. I have certain divs set up with an attribute of
Doing some homework here (second assignment, still extremely green...). The object is to read
Actually am doing shopping cart application , after good are transfered we are asking
$('.star').mouseover(function (){ var star = $(this).index()1; $(this).parent().css(background-position,0 - (32 * star) px); }); $('.star-rating').mouseout(function
I'm experimenting on some movie rating data. Currently doing some hybrid item and user
I have been doing some testing whilst using Jquery UI datepicker and have found
i have a page on which i have some rating function like people who
Hey, I have 10 ul.rating elements on my page. I want to refresh those

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.