Friday, February 28, 2014

azax page call script by js


<script type="text/javascript">
function callBookList(){

   alert("azaxOne");
  
  
   $.ajax({
     url:"addBookEntryDataLogIn.do",
     success:function(data){
      $("#setAzaxPage_div").html(data);
     }
   })
  
  
  alert("azaxTwo");
  
}
</script>



@@@@@@@@@@@@@@@@@@@@@@@@@

Jsp page design :
------------------
N.B : Name are same but value different
 <tr>
    <td style="text-align:right;">Status : </td>
    <td width="8%"><input id="" name="ctive" type="radio" value="1" />Active </td>
    <td width="68%"><input id="" name="ctive" type="radio" value="0" />Inactive</td>
  </tr>


or


 <tr>
    <td style="text-align:right;">Status : </td>
    <td width="8%"><input id="" name="ctive" type="radio" value="Yes" />Active </td>
    <td width="68%"><input id="" name="ctive" type="radio" value="N0" />Inactive</td>
  </tr>



NOW AZAX SCRIPT :
--------------------------------

<script type="text/javascript">
function callBookList(){

   alert("azaxOne");
  
   var booksType =  document.getElementById('booksType').value; // input box
   alert("booksType="+booksType);
  
   var booksDes =  document.getElementById('booksDes').value; // text area
   alert("booksDes="+booksDes);
  
  
   //***** Start this portion is use for get Gender radio button  value
    var radiosA=document.getElementsByName('ctive');
   alert("radiosA"+radiosA);

    var statusValA;
    for (var i = 0, length = radiosA.length; i < length; i++) {
        if (radiosA[i].checked) {
            statusValA=radiosA[i].value;     
            alert("statusValA"+statusValA);
            break;
        }
    }
  
 
  
   $.ajax({
     url: "addBookEntryDataLogIn.do?booksType="+booksType+"&booksDes="+booksDes+"&statusValA="+statusValA,
     success:function(data){
      $("#setAzaxPage_div").html(data);
     }
   })
  
  
  alert("azaxTwo");
  
}
</script>






As  Combo value get :
------------------------------
var dt3 = document.getElementById('bank_name');  // As combo
var bankName = dt3.options[dt3.selectedIndex].value;
alert("bankName"+bankName);







@@@@@@@@@@@@@@@@@@@@@@@@@@
If i need another function create :then -

<!-- **** Start tab pane ****  -->
<script type="text/javascript">
function callBookList(){

   alert("azaxOne");
  
   var booksType =  document.getElementById('booksType').value;
   alert("booksType="+booksType);
  
   var booksDes =  document.getElementById('booksDes').value;
   alert("booksDes="+booksDes);
  
  
   //***** Start this portion is use for get Gender radio button  value
   //gender(genderOne,genderTwo,genderThree)
   var radiosA=document.getElementsByName('ctive');
   alert("radiosA"+radiosA);

    var statusValA;
    for (var i = 0, length = radiosA.length; i < length; i++) {
        if (radiosA[i].checked) {
            statusValA=radiosA[i].value;    
            alert("statusValA"+statusValA);
            break;
        }
    }
  
 
  
   $.ajax({
     url: "addBookEntryDataLogIn.do?booksType="+booksType+"&booksDes="+booksDes+"&statusValA="+statusValA,
     success:function(data){
      $("#setAzaxPage_div").html(data);
       clear();
     }
   })
  
  
  alert("azaxTwo");
  
}



function clear(){
  alert("cL");
  document.getElementById('booksDes').value = "";
  document.getElementById('booksType').value = "";

 
 
   
}
</script>
<!-- **** End tab pane ****  -->



AND JSP Page is  :
................................
................................

<table width="100%" border="0" cellspacing="1" cellpadding="1" style="font-family:Arial; font-size:12px; font-weight:bold; color:#000;">
  <tr>
    <td colspan="3" style="font-family:Arial; font-size:13px; font-weight:bold; color:#000; padding:5px; background:#D5E0F4;">Books Type Entry Setup Form : </td>
    </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
    </tr>
  <tr>
    <td width="24%" style="text-align:right;">Books Type : </td>
    <td colspan="2"><input id="booksType" name="" type="text" value="" /></td>
    </tr>
  <tr>
    <td style="text-align:right;">Description : </td>
    <td colspan="2"><textarea  id="booksDes" name="" ></textarea ></td>
    </tr>
  <tr>
    <td style="text-align:right;">Status : </td>
    <td width="8%"><input id="" name="ctive" type="radio" value="1" />Active </td>
    <td width="68%"><input id="" name="ctive" type="radio" value="0" />Inactive</td>

  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td style="padding-bottom:10px;"><input id="" name="" type="button" value="Save" onclick="callBookList();"/></td>
    <td>&nbsp;</td>
  </tr>
   <tr>
    <td colspan="3">&nbsp;</td>
    </tr>
</table>













@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
Azax page call same div with status maintain : Learn it from java action class file for java code
-----------------------------------------------------------------------------------------------------------------------------
jsp page :



Now function call on active or inactive :

<div id="divs_id" style="float:left; width:100%; height:auto;">
      <table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr style="background:#666699;font-family:Arial;font-size:14px;font-weight:bold;color:#FFFFFF; text-align:center;">
    <td colspan="6" style="padding:5px;">User  Data Type</td>
    </tr>
  <tr style="background:#666699;font-family:Arial;font-size:14px;font-weight:bold;color:#FFFFFF; text-align:center;">
    <td width="22%" height="42" style="padding:5px;">User id</td>
    <td width="20%">Password</td>
    <td width="16%">User full name</td>
    <td width="11%">Role</td>
    <td width="18%">Image</td>
    <td width="13%">Inactive/Active Status</td>
  </tr>
  <s:iterator value="userDataTableList"  status="rowstatus">   
  <tr style="text-align:center;">
    <td><input id="pId" name="pInactiveId"  value="<s:property value='id'/>" type="hidden"   /><s:property value='user_id'/></td>
    <td><s:property value='user_pass'/></td>
    <td><s:property value='user_full_name'/></td>
    <td><s:property value='urd_name'/></td>
    <td>pic</td>
    <td><a href="#"  onClick="userStatusCall('<s:property value="status"/>','<s:property value="id"/>');"><s:property value='status'/></a></td>
  </tr>
  </s:iterator>
  <tr style="text-align:center;">
    <td colspan="6"><input id="" name="" type="button" value="Save" onClick="callActiveList();"/></td>
  </tr>
</table>
</div>

Not :(n.b: Not Single cotation) onClick="userStatusCall('<s:property value='status'/>','<s:property value'id'/>');"




<!-- **** Start tab pane ****  -->
<script type="text/javascript">
function userStatusCall(statusVal,unikId){


 alert("azaxTTwo_2 :"+statusVal);
 alert(unikId);
   $.ajax({
     url:"userStatusLogIn.do?statusVal="+statusVal+"&unikId="+unikId,
     success:function(data){
      $("#divs_id").html(data);
     }
   })
  alert("azaxTThree_3");
  

}
</script>



Java action class file :
//Azax
    private String statusVal;
    private String unikId;
    private String status = "";//Not set get just use for condition apply
    public String userStatus(){
        System.out.println("azax page: statusList call");
        if(statusVal.equalsIgnoreCase("inactive")){
            status ="1";
        } else {
            status ="0";
        }

        UserDataTableSQL userDataTableSQL = new UserDataTableSQL();
        userDataTableSQL.getUpdateTable(status,unikId); // use for update query
        userDataList(); // use for select query
        return "userStatus";
    }
    
Note : Hare I have take Uppercase Inactive value from jsp page But no problem  because I have used equalsIgnoreCase
 Now sql file :

//================user table: KYAMC_USER_TYPE
    public List getUserData() {
        List userDataTableList = new ArrayList();

        boolean fg = true;
        this.con = this.dbc.connectDB();

        if (this.con == null) {
            fg = false;
        }

        if (fg) {
            try {
                this.st = this.con.createStatement();

                //String query = "SELECT ID,USER_ID,USER_PASS,USER_FULL_NAME,GROUP_ID FROM  KYAMC_USER_TYPE";
                //String query = "SELECT ID,USER_ID,USER_PASS,USER_FULL_NAME,GROUP_ID FROM  KYAMC_USER_TYPE where STATUS='0'";
                //String query = "select id,user_id,user_pass,user_full_name,group_id,(select urd_name from kyamc_roledata_details where urd_grouporrole_id =a.group_id ) urd_name from  kyamc_user_type a  where status='0'";
               
                String query = "select id,user_id,user_pass,user_full_name,group_id,(select urd_name from kyamc_roledata_details where urd_grouporrole_id =a.group_id ) urd_name, decode(status,'1','Active','Inactive') status from  kyamc_user_type a";
               
                this.rs = this.st.executeQuery(query);
               

                while (this.rs.next()) {
                    UserDataTableInfo userDataTableInfo = new UserDataTableInfo();
                    //accountLevelInfo.setAuto_ac_type_no(this.rs.getString("AUTO_AC_TYPE_NO").trim());
                    userDataTableInfo.setId(this.rs.getString("id"));
                    userDataTableInfo.setUser_id(this.rs.getString("user_id"));
                    userDataTableInfo.setUser_pass(this.rs.getString("user_pass"));
                    userDataTableInfo.setUser_full_name(this.rs.getString("user_full_name"));
                    userDataTableInfo.setGroup_id(this.rs.getString("group_id"));
                    userDataTableInfo.setUrd_name(this.rs.getString("urd_name"));
                    userDataTableInfo.setStatus(rs.getString("status"));
                    userDataTableList.add(userDataTableInfo);
                }
            } catch (SQLException sq) {
                sq.printStackTrace();
                //or below line
                //System.out.println("Account Information Name Query Exception "+ sq.getMessage());
                try {
                    if (this.rs != null) {
                        this.rs.close();
                    }
                   

                    this.con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            } finally {
                try {
                    if (this.rs != null) {
                        this.rs.close();
                    }

                    this.con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return userDataTableList;
    }
   
   
   
   
   
   
    //***************************************************************** START
    //***************************************************************** START
   
    //========================= update  query(executeUpdate) / insert query
      public void getUpdateTable(String statusPosition,String booksSingleId){
          System.out.println("kaniz");
          boolean fg = true;
          con = dbc.connectDB();

           if (con == null) {
               fg = false;
           }
      
      if (fg) {
       try {

              st = con.createStatement();
    
   //update kyamc_user_type set Status = '0' where ID='1130000019'
String queryUpdate = "update kyamc_user_type set Status = '"+statusPosition+"' where ID='"+booksSingleId+"'";

     System.out.println("QueryUpdate" + queryUpdate);
      //st.execute(query);//It is use for insertQuery
      st.executeUpdate(queryUpdate);
    

  


      } catch (SQLException sq) {       
        sq.printStackTrace();
      } finally {
        try {
            if (rs != null) {
                rs.close();
            }
      
            con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
      }
      }
  
              //return "getBankInfoPageReturn";  //Remember UPDATE query not Return;.Only select query return List.
          }
     
   
   
    //***************************************************************** END
    //***************************************************************** END
   
   













No comments:

Post a Comment