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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:11+00:00 2026-05-28T22:08:11+00:00

Can some one tell me how to pass variable Y to $(‘a:eq(0)’).click() ? I

  • 0

Can some one tell me how to pass variable Yto $('a:eq(0)').click()? I need to alert the server respond to the .click() function. I am using a PHP framework if that’s important.

<script>
    $(document).ready(function() {
        function clockIn(str){
            if (window.XMLHttpRequest)
            { // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    document.getElementById("message").innerHTML=xmlhttp.responseText;
                    var y = xmlhttp.responseText ; 

                }
            }
            xmlhttp.open("GET","http://localhost/gasstation/index.php/welcome/check_time_clock/"+ str,true);
            xmlhttp.send();
        } 

        $( "input:submit, a", ".login" ).button();

        $("a:eq(0)").click(function(){
            clockIn(<?php echo $emp_id; ?>);
        });

        $("a:eq(1)").click(function(){
            alert('m') ;
        })
    });
</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-05-28T22:08:11+00:00Added an answer on May 28, 2026 at 10:08 pm

    Since you are making an ajax call you have to wait until the server responds so you cannot get the value of y inside click hanlder. You can pass a handler to clockIn and then execute it once the ajax response comes. Try this.

    function clockIn(str, callback){
       ...
       xmlhttp.onreadystatechange=function()
       {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
            document.getElementById("message").innerHTML=xmlhttp.responseText;
            var y = xmlhttp.responseText ; 
            callback(y);
          }
       }
       ...
    }
    
    
    $("a:eq(0)").click(function(){
       clockIn("<?php echo $emp_id; ?>", function(y){
          //You will get the value of y here.
          alert(y);
       });
    });
    

    Since you are using jQuery you should leverage it completly to make your code simple and clean. Instead of creating write the code your own to create xmlhttp request object and bla bla you can smply use $.ajax of jQuery for the same use. Your code will become like this.

    function clockIn(str, callback){
       $.ajax({
          url: "http://localhost/gasstation/index.php/welcome/check_time_clock/"+ str,
          success: function(data){
             $("#message").html(data);
             callback(data);
          }
       });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can some one tell me how to pass data from controller to a data
Can some one tell me how do i display real time in c++. what
Can some one please tell me why exactly classes were introduced in C++. Are
Please can some one briefly tell me with example what does the means of
I'm after some help with jquery. Can some one tell me the best way
Question can some one tell me how can i convert my SVG element to
need some help with saxon.net. Can anybody tell me how to output a xslt
I'm new to Notepad++. Can someone tell how to pass an argument when I
Can someone tell me how can I select the Row under the one on
Can someone tell me why I'm getting successCallback is not a function in my

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.