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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:38:33+00:00 2026-06-02T00:38:33+00:00

I am facing a strange problem with JavaScript, I am working on an ajax

  • 0

I am facing a strange problem with JavaScript, I am working on an ajax database. The login form of the Database sends the data to the PHP controller with an ajax request/function. I have an error-displayer invisible div(named errorDiv) on the login page. errorDiv html is:

<div id="errorDiv" style="visibility:hidden; display:none">
...
</div>

When both the username and password fields in the login form are left empty, I need the PHP controller to response, show the login form and run a JavaScript function “DisplayLoginError()” which will make the error div visible and display the error message(please fill both the fields) in the error-div.DisplayLoginError() function’s code is:

function DisplayLoginError()
{
document.getElementById('errorDiv').style.visibility="visible";
document.getElementById('errorDiv').style.display="block";
document.getElementById('errorDiv').innerHTML = "<?php echo $loginerror; ?>";
}

The php controller code is:

if(isset($_REQUEST['login']))
{
if(isset($_REQUEST['username']) && isset($_REQUEST['password']))
    {
    .....Both the fields are filled...
    }
else   /*===Error:Any of the username or password field has  been left empty====*/
    {
    $loginerror='Please fill both the Fields to login.';
    include $_SERVER['DOCUMENT_ROOT'].'\hospital\includes\collegedata\login-form.html.php';
    }
}

Now the problem is that it can’t be done as most javascript events are user-action-triggered. For the time-being I have assigned the form tag a mouseover event which when triggered run the DisplayLoginError function and displays the error in the errorDiv.

<form onmouseover="DisplayLoginError()"> ..... </form>

But its not the proper solution. I need an event which can run this function while loading only the login div not the whole page. I can’t use the onload event here as its an ajax Database where the main page remains still only div’s change. May be the time events can be used for this purpose… I am not sure…May be there is some better solution… How can I do it with ajax?

  • 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-02T00:38:35+00:00Added an answer on June 2, 2026 at 12:38 am

    You can use lost focus event in javascript. I can’t understand your query clearly. So this is just a suggestion.

    <div id='errorDiv' >
    </div>
    Username : <input type="text" name="username" id="uname" onBlur="checkUsername();">
    Password : <input type="text" name="password" id="pword" onBlur="checkValues();">
    
    <script type="text/javascript">
    function checkValues()
    {
        uname = document.getElementById('uname').value;
        pword = document.getElementById('pword').value;
        if(uname=="" || pword=="") {
            document.getElementById('errorDiv').innerHTML="Please fill both the fields";
        }else{
            document.getElementById('errorDiv').innerHTML="";
        }
    }
    function checkUsername()
    {
        uname = document.getElementById('uname').value;
        if(uname==""){
            document.getElementById('errorDiv').innerHTML="Please enter username";
        }else{
            document.getElementById('errorDiv').innerHTML="";
        }
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing a strange problem with NSUsrDefaults. Whenever I'm fetching the data from NSUserDefaults,
I am working in a legacy code, and I am facing a strange problem.
I'm currently facing a strange problem in PHP. I have two scripts, index.php which
I am facing this strange problem while working with Generic Base Classes. I am
I am facing a really strange problem with Core Data. Let's describe it: Definitions
I am facing a strange problem. My PHP page has following code. echo <div
I'm facing very strange problem - my app is working nice on a device
I am facing a strange problem on my Ubuntu Karmic system. When I call
I am facing a strange problem with my iphone. It shows available memory as
I am facing very strange problem. After debugging from my side, I thought to

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.