English 中文(简体)
夸大一刀片的活动,在另一半天展示错误文字,并作出亚x反应
原标题:Triggering a javascript event to display error text on an another div with an ajax response

我正与 Java文一道面对一个奇怪的问题,我正在建立一个jax数据库。 数据库的标志性表格将数据发送给PHP控制器,同时提出分析要求/功能。 我在标识页上有一个错误的显示器(称为错误Div)。 差错 离婚:

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

当标识表中的用户名和密码领域都空出时,我需要PHP控制器做出反应,显示标识表,并运行 Java“DisemloginError()”功能,使错误变得明显,并在错误四中显示错误信息(请填平这两个领域)。 显示仪表显示器码:

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 ]. hospitalincludescollegedatalogin-form.html.php ;
    }
}

现在的问题是,由于大多数 j印事件是用户错开的,因此无法做到这一点。 就时间而言,我指派了标号为湿度活动,在启动显示仪表显示仪表显示仪表显示错误。

<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?

最佳回答

你们可以在javascript中利用失去的焦点活动。 我可以清楚地理解你提出的问题。 因此,这只是一项建议。

<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>
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签