2017년 4월 2일 일요일

Select option up/down

 <script type="text/javascript"> 

  function moveOption(updown, refId){
  if(typeof $("#" + refId + " option:selected").val()=="undefined"){
alert("None Selected");
return false;
}

if(updown=="up"){
  $("#" + refId + " option:selected:first-child").prop("selected", false);
  before = $("#" + refId + " option:selected:first").prev();
    $("#" + refId + " option:selected").detach().insertBefore(before);
}else{
$("#" + refId + " option:selected:last-child").prop("selected", false);
after = $("#" + refId + " option:selected:last").next();
$("#" + refId + " option:selected").detach().insertAfter(after);
}
  }

  $().ready(function() {  

$('.up-button').click(function(){
var refId=$(this).attr("ref-id");
moveOption("up", refId);
});

$('.down-button').click(function(){
var refId=$(this).attr("ref-id");
moveOption("down", refId);
});

$('#select1').find('option').css("height", "20px");
$('#select1').find('option').css("padding-top", "9px");

$('#select2').find('option').css("height", "20px");
$('#select2').find('option').css("padding-top", "9px");
  });  
 </script>  

<form> 

<div>  
  <select multiple id="select1" name="select1">
    <option value="pankaj">aasfddf</option>   
    <option value="aashish">basdfsfd</option>   
    <option value="vikram">casdfasdf</option>   
    <option value="mohit">dasdfasdf</option>  
  </select>  
  <table>
<tr>
<td>
<input type="button" class="up-button" ref-id="select1" value="&#9650;"> <input type="button" class="down-button" ref-id="select1" value="&#9660;">
</td>
</tr>
</table>  
</div> 
<div>  
  <select multiple id="select2" name="select2">
    <option value="pankaj">aasfddf</option>   
    <option value="aashish">basdfsfd</option>   
    <option value="vikram">casdfasdf</option>   
    <option value="mohit">dasdfasdf</option>  
  </select>  
  <table>
<tr>
<td>
<input type="button" class="up-button" ref-id="select2" value="&#9650;"> <input type="button" class="down-button" ref-id="select2" value="&#9660;">
</td>
</tr>
</table>  
</div>  
<br>
<input type="submit" value="Submit">
</form>



2017년 1월 22일 일요일

ajax cross domain

@RequestMapping(value="/crossAjax")
@ResponseBody
public String crossAjax(HttpServletRequest request){
String callback=request.getParameter("callback");
System.out.println("-----" + callback);
System.out.println("-----" + request.getParameter("query"));
JSONObject obj=new JSONObject();
try {
obj.put("message", "test1");
obj.put("time", "test1");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println(obj.toString());
return callback + "(" + obj.toString() + ")"


}


        $.ajax({
               url : "http://127.0.0.1:8080/home/crossAjax",
       data : {query:"select * from ssssss"},
       dataType : "jsonp",
       jsonp : "callback",
       success: function(data) {
   console.log('성공 - ', data);
       },
               error: function(xhr) {
  alert('실패 - ' +  xhr.statusText);
       }
        });

2017년 1월 14일 토요일

postgresql update or insert

CREATE TABLE test2 (id integer primary key, b varchar(10), c varchar(10), dt timestamp with time zone);

UPDATE test2 SET dt=CURRENT_TIMESTAMP WHERE id=1;
INSERT INTO test2 (id, b, c, dt)
       SELECT 1,'xxx', 'xZ', CURRENT_TIMESTAMP
       WHERE NOT EXISTS (SELECT 1 FROM test2 WHERE id=1);