Friday, 6 September 2013

While keeping JS code in external JS file not working

While keeping JS code in external JS file not working

So this is my first question on SO.I am newbie, working on an old project
and trying to keep JavaScript code in external js files but unfortunately
it is not working fine. Even though JS file is accessible and giving
proper alert if I am keeping alert to test any where. I looked at: here
and few similar questions.
After googling hours feeling helpless.
My Js file(Not using any other JS file for JSP except this):
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url :
"<%=request.getContextPath()%>/autoCompleteAction",
dataType : "json",
data : {
name_startsWith : request.term,
"boxName" : "B2"
},
success : function(data) {
response( $.map( data.countries,
function( item ) {
return {
label: item ,
value: item
};
}));
}
});
},
minLength : 1,
select : function(event, ui) {
log(ui.item ? "Selected: " + ui.item.label
: "Nothing selected, input was " +
this.value);
},
open : function() {
$(this).removeClass("ui-corner-all").addClass(
"ui-corner-top");
},
close : function() {
$(this).removeClass("ui-corner-top").addClass(
"ui-corner-all");
}
});
$( "#search" ).autocomplete({
source: function( request, response ) {
$.ajax({
url :
"<%=request.getContextPath()%>/autoCompleteAction",
dataType : "json",
data : {
//Name of the Search Box in DB
boxName:"B1",
name_startsWith : request.term
},
success : function(data) {
response( $.map( data.countries,
function( item ) {
return {
label: item ,
value: item
};
}));
}
});
},
minLength : 1,
select : function(event, ui) {
log(ui.item ? "Selected: " + ui.item.label
: "Nothing selected, input was " +
this.value);
},
open : function() {
$(this).removeClass("ui-corner-all").addClass(
"ui-corner-top");
},
close : function() {
$(this).removeClass("ui-corner-top").addClass(
"ui-corner-all");
}
});
$( "#location" ).autocomplete({
source: function( request, response ) {
$.ajax({
url :
"<%=request.getContextPath()%>/autoCompleteAction",
dataType : "json",
data : {
//Name of the Search Box in DB
boxName:"B3",
name_startsWith : request.term
},
success : function(data) {
response( $.map( data.countries,
function( item ) {
return {
label: item ,
value: item
};
}));
}
});
},
minLength : 1,
select : function(event, ui) {
if(null != document.getElementById("location")){
document.getElementById("location").value =
ui.item.label;
}
if(null !=
document.getElementById("locationLabel")){
document.getElementById("locationLabel").innerHTML
= ui.item.label;
}
log(ui.item ? "Selected: " + ui.item.label
: "Nothing selected, input was " +
this.value);
},
open : function() {
$(this).removeClass("ui-corner-all").addClass(
"ui-corner-top");
},
close : function() {
$(this).removeClass("ui-corner-top").addClass(
"ui-corner-all");
}
});
});
function displaySearchResults(path){
document.headerPage.action=path+"/resolutionAction?isSearch=true";
document.headerPage.submit();
}
function displayResults(e){
var path = '<%=getContextPath%>';
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13){
document.headerPage.action=path+"/resolutionAction?isSearch=true";
document.headerPage.submit();
}
}
function getTheLocation(locValue) {
$.ajax({
url : "<%=request.getContextPath()%>/homePageAction",
data : {
location : locValue,
isLocationChanged:"true"
},
success : function(data) {
if(null != document.getElementById("location"))
document.getElementById("location").value=locValue;
if(null != document.getElementById("locationLabel")){
document.getElementById("locationLabel").innerHTML
= locValue;
}
}
});
}
function fillLocationOnBlur(locValue){
alert("in fillLocationOnBlur() ");
alert(locValue);
document.getElementById("location").value=locValue;
}
function displayResultOnhitEnter(e){
var unicode=e.keyCode? e.keyCode : e.charCode ;
if(unicode == 13){
document.headerPage.action="<%=request.getContextPath()%>/resolutionAction?isSearch=true";
document.headerPage.submit(); }
}
In jsp file I am using this JS in last like below: (Previously JS was on
same jsp page and it was working fine)
<script
src="<%=request.getContextPath()%>/scripts/header-displaySearchResult.js">
</script>
Any help will be appreciated.

No comments:

Post a Comment