Friday, December 28, 2007

How to close a pop-up window automatically after 5 seconds through JS

setTimeout('self.close()',500);

Tutorial one and two on setTimeout.

This link and this explains clearly about the functionality.

Monday, December 17, 2007

Disabling a button using JS

function disableButton (button1,button2)
{

document.getElementById(button1).disabled=true;
document.getElementById(button2).disabled=false;


document.forms[0].button1.readonly=true;
document.forms[0].button1.disabled=true;

}

Wednesday, December 12, 2007

To get the desired message as pop-up

To get a desired message as pop-up like

1. "Do you want to save?" with a YES/NO button
2. "Do you want to submit?" with a YES/NO button

we cannot achieve the same using Javascript. We can achieve using VB script (confirm.vbs).

Function vbMsg(isTxt,isCaption)
testVal = MsgBox(isTxt,4,isCaption)
isChoice = testVal
End Function

Here is the invoking js (confirm.js).

Here title/caption is nothing but the page heading.

var isChoice = 0;
function callAlert(Msg,Title){
txt = Msg;
caption = Title;
vbMsg(txt,caption)
if(isChoice==6){
return true;
}
return false;
}

Finally here is how we invoke it

function approveRequest(approvMsg,confirmMsg){
var confirm=callAlert(approvMsg, confirmMsg);

if(confirm) {
document.forms[0].action='abcApprove.do';
document.forms[0].submit();
}
}

JSP Page


<script type="text/javascript" src="../js/confirm.js" />
<script type="text/VBScript" src="../vbs/confirm.vbs" />

<input type="button" value="<bean:message key="request.btn.approve" bundle="gtem"/>"
onClick="approveRequest('<bean:message key="request.message.approveMessage" bundle="abc"/>','<bean:message key="common.message.confirmMessage" bundle="abc"/>');">


Application Resource Bundle:

common.message.confirmMessage = Do you really want to approve request?
request.message.approveMessage = Confirm