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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:33+00:00 2026-05-26T05:45:33+00:00

I am trying to do this: Have the user click some action. The action

  • 0

I am trying to do this:

Have the user click some action. The action checks whether the user is logged in or not. If not, open a login dialog box, and if the user logs in correctly, update the original page.

I got almost all this working except the part of after successful login. The problem is that the code seems to not have access to the item_id which I was trying to update. Instead, when I try to set the item id (problem_id in this case) in the login form of the popup box, the id is the number of the id that is the last one on the page, and not the one that was clicked.

Here is what I am trying to do in the jQuery:

<script type="text/javascript">
$(document).ready(function() 
{
     var $dialog = $('#loginpopup')
       .dialog({
         autoOpen: false,
         title: 'Login Dialog'
       }); 

       var $problemId = $('#theProblemId', '#loginpopup');

        $("#newprofile").click(function () 
        {
          $("#login_div").hide();
          $("#newprofileform").show();
        });

    // Called right away after someone clicks on the vote up link
    $('.vote_up').click(function() 
    {        
        var problem_id = $(this).attr("data-problem_id");

        //alert ("In vote up click, problem_id: " + problem_id );
        voteUp(problem_id);

        //Return false to prevent page navigation
        return false;       
    });

    var voteUp = function(problem_id) 
    {
        alert ("In vote up function, problem_id: " + problem_id );

        var dataString = 'problem_id=' + problem_id + '&vote=+';

        $.ajax({
                type: "POST",
                url: "/problems/vote.php",
                dataType: "json",
                data: dataString,
                success: function(data)
                {           
                    alert ("vote success, data: " + data);
                    // ? :)

                },
                error : function(data) 
                {
                    alert ("vote error");
                    errorMessage = data.responseText;

                    if ( errorMessage == "not_logged_in" )
                    {
                        //set the current problem id to the one within the dialog
                        $problemId.val(problem_id);                 

                        // Try to create the popup that asks user to log in.
                        $dialog.dialog('open');

                        alert ("after dialog was open");

                        // prevent the default action, e.g., following a link
                        return false;
                    }
                    else
                    {
                        alert ("not");
                    }

                    //alert(JSON.stringify(data));
                } // Closing error case
            }); // Closing AJAX call.
    };

    $('.vote_down').click(function() 
    {
        alert("down");

        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=-';        

        //Return false to prevent page navigation
        return false;
    });    

    $('#loginButton', '#loginpopup').click(function() 
    {
    alert("in login button fnction");
            $.ajax({
                url:'url to do the login',
                success:function() {
                    //now call cote up 
                    voteUp($problemId.val());
                }
            });
        });    
});
</script>

and here is the login form:

         <div id="login_div">
         <form id="login_form" method="post" action="">
         <p>
             <label for="name"><span>Your Email:</span></label> <input type="text" name="email" id="email" />
         </p>
         <p>
             <label for="name"><span>Your Password:</span></label> <input type="password" name="user_pass" id="user_pass">
         </p>

         <input type="hidden" id="problem_id" name="problem_id" value="<?php echo $problem_id; ?>" />

<span class="no_such_user" style="color: red; display:none">The login and password does not match our records.</span>
<span class="password_error" style="color: red; display:none">The password much be 5 characters or more.</span>
<span class="login_success" style="color: green; display:none">You successfully logged in.</span>
         <p>
            <input type="submit" value="Log In"  />
         </p>
         </form>

         </div>

But the problem_id which is being set in this form isn’t the one being clicked on, even though I am trying to save it in my jQuery.

Also, here is the code that gets executed for login:

$(function()
{
    $("#login_div input[type=submit]").click(function()
    {
        var email = $("#email").val();
        var password = $("#user_pass").val();

        //alert("Email: " + email);
        //alert("password: " + password);

        var dataString = 'email='+ email + '&password=' + password;

        if( !email )
        {   
            alert ("1");
            $('.login_success_email_empty').fadeOut(200).hide();
            $('.login_error_email_empty').fadeOut(200).show();
        }       
        else        
        if( !password || password.length < 5)
        {alert ("2");
            $('.password_success').fadeOut(200).hide();
            $('.password_error').fadeOut(200).show();
        }
        else
        {
            $.ajax({
                type: "POST",
                url: "../auth/login_ajax.php",
                dataType: "json",
                data: dataString,
                success: function(json)
                {
                    $('.password_error').fadeOut(200).hide();
                    $('.no_such_user').fadeOut(200).hide(); 
                    $('.login_success_email_empty').fadeOut(200).hide();
                    $('.login_success').fadeIn(200).show();                                 

                    // Closing the dialog bosx
                    $('#loginpopup').dialog('close');

                    // Swapping out the header div
                    $('#header_logged_out').hide();
                    $('#header_logged_in').show();  

                    // Now also need to retrieve the problem_id                 
                    problem_id = $("#problem_id").val();
                    //$problemId = $('#theProblemId', '#loginpopup').val();         


                    var $problemId = $('#theProblemId', '#loginpopup');
                    alert ("After login, problem_id: " + problem_id + " and problemId was: " + $problemId);
                },
                error : function(json)
                {
                    alert ("error");

                    // Output the result.
                    errorMessage = json.responseText;

                    alert ("ErrorMessage: " + errorMessage );

                    if ( errorMessage == 'no_such_user' )
                    {
                        $('.no_such_user').fadeOut(200).hide();
                        $('.no_such_user').fadeOut(200).show();                 
                    }
                }
            });
        }

        return false;
    });
});

and I am just not sure how to get that problem_id which was set in the original jQuery code to be recognized in the jQuery code that executes after login.

Because what I really need to do is update that particular problem depending on whether the user was logged in.

And how do I know in the original code that processes the votes, whether the login in the dialog box was successful or not?

By the way, I am working on this page: http://www.problemio.com

  • 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-26T05:45:34+00:00Added an answer on May 26, 2026 at 5:45 am

    It seems that you might be better served using the jquery forms /ajax submit plugin:
    http://be.twixt.us/jquery/formSubmission.php

    $('loginDiv > form').submit(function() {
        var options = {
            url = "../auth/login_ajax.php",
            [...]
           };
        $(this).ajaxSubmit(options);
        return false;  //this line is required to make sure that the page doesn't get redirection to /auth/login_ajax.php
    });
    

    This way it won’t reload any of the javascript, preserving any variables that have already been set. You can therefore set the problem ID before the login, and then do stuff with it afterward.

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

Sidebar

Related Questions

I'm trying to figure out why this is happening. I'll have the user be
I'm trying to have this block element to be horizontally aligned in the middle
I'm trying this for almost two hours now, without any luck. I have a
Is there anyone who knows this? I have been trying this for the last
I have this problem I've been trying to tackle for a while. I have
Ok I have this problem I'm trying to use Jquery to load a partial
I have this output when trying to debug Program received signal SIGSEGV, Segmentation fault
I have this piece of code I'm trying to get to display but no
I have this string containing a large chunk of html and am trying to
I have this code in my ASP.NET application written in C# that is trying

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.