Jquery Autocomplete token input does'nt work in safari and chrome - java

Autocomplete token input box works properly in IE and Firefox but it doesn't work in safari and crome.
this is a part of code
<script type="text/javascript" src="<%=path%>/js/jquery-1.4.4.min.js"></script>
//for auto complete
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jqueryAutocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jqueryAutocomplete/jquery.ajaxQueue.js"></script>
<link type="text/css" media="screen" rel="stylesheet" href="<%=request.getContextPath()%>/css/jqueryAutocomplete/jquery.autocomplete.css" />
$j(document).ready(function(){
$j("#id_CBRERegion").tokenInput(path + "fetchAutoCompleteResult.do?method=regionList", {
theme: "facebook",
queryParam: "search",
minChars: 1,
preventDuplicates: true,
hintText:"CBRE Region",
prePopulate: selRegCode
});
$j('#id_CBRERegion').prev().find("input").blur();
registerAutoEvent('id_CBRERegion','id_CBRERegion_Temp');
if(document.getElementById('id_CBRERegion').value != "") {
$j('#id_CBRERegion_Temp').hide();
} else if(document.getElementById('id_CBRERegion').value == "") {
$j('#id_CBRERegion_Temp').next().hide();
}
});
Please suggest..

I just visited http://jqueryui.com/demos/autocomplete/ in Chrome and Safari and it works.
Many factors could be causing the problem, from css to data.
Best way to resolve and learn the function.
start from a simple example off the site
Add in your bits slowly until you see it fail.

Related

Struts 2 jQuery plugin isSubscribe not working

The struts 2 jQuery plugin has a built in publish/subscribe framework.
If you define your own publish and subscribe event (for example on a grid) the subscribed function will be called every time the event is published. For details please see (Struts 2 jQuery Subscribe is called more than once)
To prevent this, there is a isSubscribed method which can be used.
For a grid as:
<sjg:grid id="gridtable"
onBeforeTopics="before_grid_load" >
The JS will be:
$.subscribe('before_grid_load', function(event, data) {
if ( $('#gridtable').isSubscribed('before_grid_load') ){
return ;
}
//go on with function
}
The problem is that the $('#gridtable').isSubscribed('before_grid_load') returns false every time!
The function isSubscribed is applied on the element $('#gridtable') but subscribed to the $(document). I have tested with the last element and it didn't work to me. But tried with the first element and it worked.
Script:
<head>
<link href="<s:url value="/css/template_styles.css"/>" type="text/css" rel="stylesheet">
<sj:head />
<title>jQuery Grid</title>
<script type="text/javascript">
$(document).ready(function(){
console.log("Before subscribe");
$("#gridtable").subscribe("beforeTopic", function(topic, data) {
console.log('Topic: '+data, topic);
if ( $("#gridtable").isSubscribed("beforeTopic") ){
console.log('Subscribed: '+data, topic);
return;
}
//go on with function
console.log('Not subscribed: '+data, topic);
});
console.log("After subscribe");
});
</script>
</head>
For grid:
<sjg:grid id="gridtable"
onBeforeTopics="beforeTopic" >
Check your lib to your jsp
<%# taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
Enable jQuery Grid Plugin in your Head Tag
<sj:head jqueryui="true" jquerytheme="redmond" />

opening a window in a target frame

I have a website and ran into an issue.
First of all the website is in dutch however the problem i have you don't have to understand dutch.
My website is www.hobbysite.zz.mu/
When you click the login button it redirects you to a mybb forum login (this is correct)
next part is the tricky part for me.
when you click the login button there it should run this script:
<html> <head>
<script language="Javascript">
function trigger(){
document.php-form.submit();
document.htm-form.submit(); }
</script> </head>
<body onload="trigger();">
<form name="php-form" action="http://hobbysite.zz.mu/top.html" target="_topframe">
<form name="htm-form" action="http://hobbysite.zz.mu/Main/main.html" target="mainframe">
</body>
Problem is however that its not doing the first option and chance the "cloud" set.
my first cloudset iswww.hobbysite.zz.mu/top1.html and it should chance in the target frame topframe to hobbysite.zz.mu/top.html
thanks in advance
Instead of trying to submit two forms you could change the location of the frames. Try this code:
<html><head>
<script>
function trigger() {
top.frames["topFrame"].location.href="http://hobbysite.zz.mu/top.html";
top.frames["mainFrame"].location.href="http://hobbysite.zz.mu/Main/main.html";
}
</script>
</head>
<body onload="trigger();">
</body></html>

Loading different stylesheet based on your users location

I have a small issue.
Im trying to develop a solution with java that will allow me to load a specific stylesheet based on the users location.
I am not that well versed in scripting things myself and typically use jquery plugins.
If you could help me out with a little code to get me started or point me in the direction of some tutorials that would be of immense help.
Thanks
Have a look at http://www.jquery4u.com/tag/jquery-location-api/ together with http://www.geoplugin.com/webservices/javascript .There is a complete example on how to use it. When have the location then it's up to you how you want to add/change styling.
Actually could use a little more help wiht this one.
I created a quick else if statement that i would use to load the stylesheets based on the output of the geolocator.
<script type="text/javascript">
if (geoplugin_countryName() == CA) {
<link rel="stylesheet" type="text/css" href="main_css.css" media="screen" />
}
else if (geoplugin_countryName() == US) {
<link rel="stylesheet" type="text/css" href="main_css.css" media="screen" />
}
else if (geoplugin_countryName() == EU) {
<link rel="stylesheet" type="text/css" href="main_css.css" media="screen" />
}
</script>
If someone could take a look at this code and let me know if the syntax will work that would be awesome, as it stands im not too familiar with java.
Thanks

Problem with jquery and IE 8 and later

In Firefox work, but when load page in IE8 i get only blank page and source HTML-code available.
I delete
<script src="/NewsManager/js/jquery.js"
type = "text/javascript"
</script>
and all work without script.
NetBeans 6.7, ApacheTomcat, JSP
You missed the closing > in second line:
<script src="/NewsManager/js/jquery.js"
type = "text/javascript"> <!-- close the opening script tag HERE -->
Try this:
<script src="/NewsManager/js/jquery.js" type="text/javascript"></script>

Closing open XML tags with regex

Basically I want to do the same as here which is done in Python.
I'd like to replace all self-closed elements to the long syntax.
Example
<iframe src="http://example.com/thing"/>
becomes
<iframe src="http://example.com/thing"></iframe>
Full example:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/sample.css">
<title></title>
<script type="text/javascript" src="/swfobject.js">
//void
</script>
<script type="text/javascript" language="JavaScript" src="/generate.js">
//void
</script>
<script type="text/javascript" language="JavaScript" src="/prototype.js">
//void
</script>
</head>
<body id="mediaPlayer" style="margin:0;padding:0;">
<script type="text/javascript">
swfobject.registerObject('id_G12564763');
function getFlashObject() {
var object;
if (navigator.appName == 'Microsoft Internet Explorer' || navigator.userAgent.indexOf("Chrome")!=-1)
{
object = document.getElementById('id_G12564763');
}
else
{
object = document['flash_id_G12564763'];
}
return object;
}
</script>
</body>
</html>
This can be used to replace one tag (code in javascript).
var becomes = "<iframe src='http://example.com/thing'/>".replace(/<(\w*) (.*)\//,'<$1 $2></$1')
The same, in Java.
String becomes = "<iframe src=\"http://example.com/thing\"/>".replaceFirst("<(\\w*) (.*)\\/", "<$1 $2></$1");
Ok guys. I found a workaround. I hooked the output method to xml where this html comes from and the XSLT engine takes care of closing those open tags for me. Thanks for answers, but if you happen to have a solution for the problem pls, leave your answer and I will mark it as an answer. This could be useful for others.
String resultHtml = inputHtml.replaceAll("(?six)<(\\w+)([^<]*?)/>", "<$1$2></$1>");
and this will properly handle tags that are not terminated like <hr> and <img>

Categories