Friday, August 24, 2012

Clear Form with jQuery

<html>

<head>
<script language="JavaScript" type="text/JavaScript" src="Script/jquery-1.8.0.min.js"></script>
</head>

<body>

<form id="frm">
          <input type="button"  value="Clear" onclick="resetForm('frm')" />
</form>

<script>
/**
* This function clears all input fields value except button, submit, reset, hidden fields
* */
function resetForm(formid) {
                  $(':input','#'+formid) .not(':button, :submit, :reset, :hidden') .val('') .removeAttr('checked').removeAttr('selected');
 
}

</script>

</body>
</html>

Thursday, August 16, 2012

scrollable div


To make the div scroll-able in vertical direction:  


<div  style="height: 300px; overflow-y: scroll">

</div>

How to view List inside list using

if you have a list inside another list, for example you want to iterate over students list and students courses 
and you want to view it in the jsp page, you can use the <s:iterator>  as follows: 

<s:iterator value="studentsList" >

        <s:property value="studentName"/>

       <s:iterator value="%{courses}" >

                      <s:property value="courseName"/>

       </s:iterator> 

</s:iterator> 


This example read the studentsList from struts action. 

Friday, August 10, 2012

How to get fields from different tables in hibernate ?



StringWriter queryS = new StringWriter(200);
Query query;

queryS.append("SELECT A.dateBilling,B.currencyCode " );
queryS.append(" from AImpl A,BImpl B ");
queryS.append("where B.id = A.id  " );


query = this.getSession().createQuery(queryS.toString());
//The values in this array are:
//dateBilling     = results[0]
//currencyCode = results[1]
Object[] results = (Object[]) query.list().get(0);

return results;

Friday, August 3, 2012

Toggles the visibility of a div by clicking on an expand/collapse image


/**
 * Toggles the visibility of a div by clicking on an expand/collapse image.
 * The obj parameter is the image link and the "id" is the id of the div to
 * toggle.
 * @param obj
 * @param id
 */
function toggle(obj,id) {
    var state = document.getElementById(id).style.display;
        if (state == 'block') {
            document.getElementById(id).style.display = 'none';
            obj.src = 'Images/Expand.png';
            obj.title = 'Click to Expand';
        } else {
            document.getElementById(id).style.display = 'block';
            obj.src = 'Images/Collapse.png';
            obj.title = 'Click to Collapse';
        }
}


// In JSP file add the following:


<img id="invoiceListImg" src="Images/Collapse.png" alt="Collapse"  title="Click to Collapse"
onclick="toggle(this,'divName');"/>