Wednesday, February 20, 2008
Formatting Date and time using JavaScript.
This link helps us in formatting the date and time in JavaScript.
Thursday, January 31, 2008
Generating dynamic date using Javascript.
function getRandomMaxMaturityDate() {
var myDate = new Date();
myDate.setDate(myDate.getDate()* (Math.random()* 555));
var date = myDate.getDay();
var month = myDate.getMonth();
var year = myDate.getYear();
document.forms[0].maxMaturityDateString.value = (month + "/" + date + "/" + year);
}
var myDate = new Date();
myDate.setDate(myDate.getDate()* (Math.random()* 555));
var date = myDate.getDay();
var month = myDate.getMonth();
var year = myDate.getYear();
document.forms[0].maxMaturityDateString.value = (month + "/" + date + "/" + year);
}
Setting parent window textbox based on pop-up window table row selection
Requirement:
I am having a parent window with a textbox and an adjacent search button. On click of the search button, a pop-up window should open with a table with 5 columns populated with rows in it and a OK button. On click of one of those rows and clicking OK button the selected row’s second column value should come and site in the parent windows text box.
JSP Code of parent page:
<td class="rmt-readOnlyRowHead" align="left" valign="top">
<span>
<html:text name="RequestForm" property="bankName" size="20" styleClass="rmt-formTxt" />
</span>
<span>
<input type="button" class="secondaryButton" id="search" value="Search"
onclick="window.open('searchBankName.do','searchBankName','resizable=1,width=710,height=650,status=1,scrollbars=1');" />
</span>
</td>
JSP Code of pop-up window:
<table id="t32bot" cellpadding="0" cellspacing="0" width="100%" border="0" id="sync">
<tbody>
<logic:iterate id="row" name="BankForm" property="bankList">
<tr id="srch_r1" clickable="yes">
<td nowrap class="rmt-tableCellTxt" onClick="clicked('t32bot',this);"> <bean:write name="row" property='countryName'/>
</td>
<td nowrap class="rmt-tableCellTxt" onClick="clicked('t32bot',this);"> <bean:write name="row" property='bankName'/>
</td>
<td nowrap class="rmt-tableCellTxt" onClick="clicked('t32bot',this);"> <bean:write name="row" property='facilityType'/>
</td>
</tr>
</logic:iterate>
</tbody>
</table>
<input type="button" class="primaryButton" id="ok" onClick="setBankName('t32bot');" value="Ok"/>
JS Code of pop-up window:
function setBankName(TABLE_NAME)
{
var bankName = window.opener.document.getElementById("bankName");
var tbl = document.getElementById(TABLE_NAME);
for (var i=0; i<tbl.tBodies[0].rows.length; i++) {
if (tbl.tBodies[0].rows[i].className.indexOf("rmt-rowClick") != -1) {
var rowElem = tbl.tBodies[0].rows[i];
var cell = rowElem.getElementsByTagName("td")[1];
bankName.value = cell.childNodes[0].data;
window.close();
}
}
}
I am having a parent window with a textbox and an adjacent search button. On click of the search button, a pop-up window should open with a table with 5 columns populated with rows in it and a OK button. On click of one of those rows and clicking OK button the selected row’s second column value should come and site in the parent windows text box.
JSP Code of parent page:
<td class="rmt-readOnlyRowHead" align="left" valign="top">
<span>
<html:text name="RequestForm" property="bankName" size="20" styleClass="rmt-formTxt" />
</span>
<span>
<input type="button" class="secondaryButton" id="search" value="Search"
onclick="window.open('searchBankName.do','searchBankName','resizable=1,width=710,height=650,status=1,scrollbars=1');" />
</span>
</td>
JSP Code of pop-up window:
<table id="t32bot" cellpadding="0" cellspacing="0" width="100%" border="0" id="sync">
<tbody>
<logic:iterate id="row" name="BankForm" property="bankList">
<tr id="srch_r1" clickable="yes">
<td nowrap class="rmt-tableCellTxt" onClick="clicked('t32bot',this);"> <bean:write name="row" property='countryName'/>
</td>
<td nowrap class="rmt-tableCellTxt" onClick="clicked('t32bot',this);"> <bean:write name="row" property='bankName'/>
</td>
<td nowrap class="rmt-tableCellTxt" onClick="clicked('t32bot',this);"> <bean:write name="row" property='facilityType'/>
</td>
</tr>
</logic:iterate>
</tbody>
</table>
<input type="button" class="primaryButton" id="ok" onClick="setBankName('t32bot');" value="Ok"/>
JS Code of pop-up window:
function setBankName(TABLE_NAME)
{
var bankName = window.opener.document.getElementById("bankName");
var tbl = document.getElementById(TABLE_NAME);
for (var i=0; i<tbl.tBodies[0].rows.length; i++) {
if (tbl.tBodies[0].rows[i].className.indexOf("rmt-rowClick") != -1) {
var rowElem = tbl.tBodies[0].rows[i];
var cell = rowElem.getElementsByTagName("td")[1];
bankName.value = cell.childNodes[0].data;
window.close();
}
}
}
Tuesday, January 29, 2008
JS code to select multiple rows from a table
JSP Page
<table id="t20bot" class="grid" width="100%">
<td width="60" onClick="clicked('t20bot',this);" ><bean:write name="row" property='countryName'/></td>
JS Function
function commonClicked(table_name, elem)
{
var rowElem = elem.parentNode;
if(rowElem.className == "rmt-rowClick" )
{
rowElem.className = "";
rowElem.oldClassName = "";
}
else
{
rowElem.className = "rmt-rowClick";
rowElem.oldClassName ="rmt-rowClick";
}
}
<table id="t20bot" class="grid" width="100%">
<td width="60" onClick="clicked('t20bot',this);" ><bean:write name="row" property='countryName'/></td>
JS Function
function commonClicked(table_name, elem)
{
var rowElem = elem.parentNode;
if(rowElem.className == "rmt-rowClick" )
{
rowElem.className = "";
rowElem.oldClassName = "";
}
else
{
rowElem.className = "rmt-rowClick";
rowElem.oldClassName ="rmt-rowClick";
}
}
Friday, December 28, 2007
How to close a pop-up window automatically after 5 seconds through JS
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;
}
{
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
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
Subscribe to:
Posts (Atom)