Thursday, June 30, 2016

How do I make a field autofocus?

<form action="demo_form.asp">
  First name: <input type="text" name="fname" autofocus><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit">
</form>

Wednesday, June 29, 2016

How to expire page on back button click in browser?

<%response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-store"); response.setHeader("Expires","0"); response.setDateHeader("Expires",-1); %>

Thursday, June 23, 2016

To restart httpd , mysql and tomcat series:

To restart httpd series:

1) login as root

# sudo su -
]$ cd /opt/Empt-Time-Mgmt-WebServ/bin
]$ ./apachectl -k restart
]$ exit



To restart mysql series :

]$ sudo su -

]$ /etc/init.d/mysql restart



To restart tomcate series:

]$ source /home/ngit/tomcat/webapps/myvillage/lib/bprofile
]$ cd ./home/ngit/tomcta/bin
]$ cd ../logs
]$ rm -rf *.log
]$ >cataina.out
]$ cd ../work
]$ rm -rf Catalina
]$ cd ../bin
]$ ./startup.sh

Wednesday, June 22, 2016

code for inline search



Step 1 : In JSP Need to place the below mentioned code

Note : In this code snippet i have placed autocomplete="false" to avoid autofill chrome settings

<div id="areadiv">
<input type='text' autocomplete="off" id='area' name='area' placeholder='Enter Area' style='width:96%;margin-left:5px;height:40px;border: 2px solid #CCC;font-size:14px;    font-weight: 600;font-family: ;border-radius: 4px 4px 4px 4px;background:white url(/tyres/images/searchhome.png) no-repeat 365px 9px;  padding-left:20px;' maxlength='50' onkeyup="getinlinesearch(event,'onkeyup');"><input autocomplete="false" class="enter_email_input"  name="whereever6" id="location6" placeholder="Enter Your City.." type="text" onkeyup="displayinlinewherever('caraccessories');" style='display:none;'></div>

Step 2 : To get area details need to place respective inline search function in before select drop down menu(i.e, city) as mentioned below

<select name="city" id ="city" class="drop_dn_tyres" onchange="getinlinesearch(event,'onchange');">  
    <option  value="0" >Select&nbsp;City</option>
   </select>

Step 3 : Include below mentioned js and css files

<link rel="stylesheet" href="/../css/jquery-ui.css">
<script src="/../js/jquery-ui.js"></script>

Step 4: Place the below mentioned css code in style

.dialog{width:100%;font: 12px/22px ; text-align:center;    font-family: Helvetica Neue,Helvetica,Arial,sans-serif;position:absolute;padding: 1px;display: none;z-index:9999; background: #232323;}
.ui-autocomplete
{
    position: absolute;
    cursor: default;
    height: 200px;
    overflow-y: scroll;
    overflow-x: hidden;
}

.ui-autocomplete .highlight {
   text-decoration: underline;
  }


.highlight {
   width: 159px;
    border-style: dotted;
    border-color: #cccccc;

  }

Step 5: Javascript Function
var newitems;
 function getinlinesearch(event,keytype)
  {
   //alert("inside");
  
   var city=document.getElementById("city").value;
   // alert(city);
  
   var i;
   var items="";

  
    i=$("#area");
    //document.index.searchward.style.background = 'url(/myvillage/images/searchhome.png) no-repeat 209px 9px';
  
   var val=i.val();
   /*code to high light autocomplete*/
   $.ajaxSetup({ cache: false });
   $.ui.autocomplete.prototype._renderItem = function (ul, item)
   {
    var term = this.term.split(' ').join('|');
    var re = new RegExp("(" + term + ")", "gi");   
    var itemlabel=item.label;
    var results=itemlabel.split("--");
    var value1=results[0];
    var value2=results[1];
    var t = itemlabel.replace(re, "<b>$1</b>");
    //var t1=t+" -- "+value2;
    return $("<li></li>")
    .data("item.autocomplete", item)
    .append("<a>" + t + "</a>")
    .appendTo(ul);
   };
   var vallength=val.length;
   if(vallength==0)
     {
     
    // Get the input element and its value
    document.getElementById("area").style.background = 'url(/tyres/images/searchhome.png) no-repeat 365px 9px';
     
     }
   //alert(keytype);
   if(keytype=="onchange")
   {
     /*$city = $('#city');
     var splitvalcity =$city.val(); 
     alert(splitvalb);
      if(splitvalcity=="default")
     {
      //alert("1");
      //$('#city').addClass('highlightbefore');
      //$('#city').removeClass('highlightafter');
      document.getElementById("city").focus();
     }
     else
     {
      //alert("2");
      //$('#city').removeClass('highlightbefore');
      //$('#city').addClass('highlightafter');
      document.getElementById("city").focus();
     }*/
   
     //window.scrollTo(0,document.body.scrollHeight);
     i.autocomplete({source: []});
     i.autocomplete("destroy");
     newitems="";
     $.get("./servlet/InlineSearch?city="+city+"&keyword="+onchange+"",function(data)
      {
       //alert("data :" +data);
       // Get each item separated by new line
       newitems=data.split("\n");
       //alert(newitems);
      document.getElementById("area").focus();
      //$('#corner').hide();
      //window.scrollTo(0, 150);
      });
   }
   else
   { 
     //$('#corner').hide();
    
     //alert("newsitems :" +newitems);
     // put those items in autocomplete! That's it!
     i.autocomplete({ width: 300,
     max: 10,
     delay: 100,
     minLength:2,
     autoFocus: true,
     cacheLength:1,
     scroll: true,
     highlight: true,
     source:newitems,
     select: function (event, ui, icon)
     {
      var charCode = (event.which) ? event.which : event.keyCode
      if(charCode==13)
      {
       i.css("background", "");
      
      }
     
       i.css("background", "none");
     
      /* do stuff with selection*/

      //alert("s");
       //window.location.hash = '#findbatterybutton';
      //window.scrollTo(0,document.body.scrollHeight);

      //$('#corner').show();
      //$('#findbatterybutton').addClass('highlight');
      //document.getElementById("focusable").focus();

       //$("#findbatterybutton").focus();
     },
     close: function ()
     {
     
       //this.value='';
       /* OR $(this).val('')*/
     }
     });
       
   }
}

Step 6: Method in Servlet

String s =  (req.getParameter("com") != null) ? (req.getParameter("com")) : "";
    LogLevel.DEBUG(5,new Throwable(),"s :"+s);

    String city =  (req.getParameter("city") != null) ? (req.getParameter("city")) : "";
    LogLevel.DEBUG(5,new Throwable(),"city :"+city);
  
    String keyword =  (req.getParameter("keyword") != null) ? (req.getParameter("keyword")) : "";
    LogLevel.DEBUG(5,new Throwable(),"keyword :"+keyword);

    Vector panchayatnamevector = new Vector();
   
    String panchayatname="select distinct(area) from location_area where location='"+city+"' order by area asc";
    LogLevel.DEBUG(5,new Throwable(),"panchayatname :"+panchayatname);
    panchayatnamevector=qm.executeQuery(panchayatname);
    
    LogLevel.DEBUG(5,new Throwable(),"panchayatnamevector :"+panchayatnamevector);
    String strRes="";
    ArrayList<String> as=new ArrayList<String>();

    s=s.toLowerCase();

    for(int j=0; j<panchayatnamevector.size();j++)
    {  
     Hashtable panchayatht=(Hashtable)panchayatnamevector.get(j);
     String area=String.valueOf(panchayatht.get("area"));
     LogLevel.DEBUG(5,new Throwable(),"area:"+area);

     String arealower=area.toLowerCase();
     LogLevel.DEBUG(5,new Throwable(),"arealower :"+arealower);
    
      if(keyword.equals("onchange"))
      {
       as.add(area);
      }
      else
      {
       if(arealower.startsWith(s))
       {
        LogLevel.DEBUG(5,new Throwable(),"if :"+arealower);      
        as.add(area);      
       }
      }
    
    }
    LogLevel.DEBUG(5,new Throwable(),"as:"+as);
  
    for(String st:as)
    {    
      out.println(st);    
    }
    out.close();

 }





How to reset dropdown list select ' dropdown' on 'back' button of browser using Javascript

You can use the 'onbeforeunload' event:

<script>
function reset_options() {
    document.getElementById('MySelect').options.length = 0;
    return true;
}

</script>

<body onbeforeunload="reset_options()">

To find out the keyword in the node

for example go to the path:  cd /home/ngit/tomcat/webapps/smarthr/

Example Keyword Haryana:

grep -H -R Haryana * | cut -d: -f1

If Else Condition for html tags


<% if(pagename.equals("agri"))
{ %>
<li>Agri Service Units  Login</li>

<% }
else

{ %>
<li> Agri Product Companies Login</li>

<% } %>

To disable copy paste for textbox

<input type="textbox" id="email" oncopy="return false" onpaste="return false" >

Ket Event Codes in javascript

http://www.asquare.net/javascript/tests/KeyCode.html

how to check create table

show create table agri_service_details;

How to redirect a website to mobile version:

--> Javascript window.location Method

--> Because mobile phones typically have a small screen width, you can redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels. You place this code in the head section of your main website code. That way when your site is visited, the javascript will see the browser width and redirect to the appropriate site

You can use the following code to do this:

<script type="text/javascript">
  <!--
  if (screen.width <= 800) {
    window.location = "http://m.domain.com";
  }
  //-->
</script>

to change the column name in a table:


mysql> alter table adaptation_officer_table change accept_invitation_activepartner accept_invitation_activepartners varchar(20);

Solution for reaching mysql:

 ** Increase Key Buffer ( yours is currently 64MB, but total indexes are 116M, so put at least 128MB). Should help immediately.
 ** Run mysqloptimize and mysqlrepair on your tables
 ** Increase table cache/ decrease total number of tables to increase the table cache hit rate. Maybe you've got some unused or old tables which could be deleted.

Other recommended confugration options:

   ** log_slow_queries = /var/log/mysql/mysql-slow.log
   ** long_query_time = 4
   ** log-queries-not-using-indexes

Check log file after some time.

-------------------------------------------------------

SET global max_connections = 1000000

show variables like 'max_connections'

mysql> show status like '%onn%';

mysql> show processlist;

To kill the mysql process

]$ sudo kill -9 process-id
]$ sudo service mysql start
]$ ps -ef | grep mysql

change the version number after changes done in the css files

WEB.XML

(GIS Version number)

history of last committed of a file:

]$ cvs log filename

shutdown and startup


]$ source /home....
]$ ./shutdown
]$ cd ../logs
]$ rm -rf *.log
]$ cd ../work
]$ rm -rf Catalina
]$ cd ../bin
]$ source ...
]$ ./startup

Remove logs:

> cd tomcat/logs
 >rm -rf *.log
 >catalina.out
> cd ../work
> sudo rm -rf Catalina
 >cd ../webapps/myvillage/logs
 >gis.log

Indexing:

show indexes from table_name. create index masters_key on qpa_survey_status (masters_key);

mysql commands:

1) create indexing for every field wherever you are using "where" condintion in the query. 2) "in " should not be used in the query instead use array list . 3) for fetching codes(pcode,ccode,dcode etc) use limit 1 for fast exceution of query.