hasan's blog (বল্গ)

work for fun!!!

Archive for the ‘javascript’ Category

internet explorer expected identifier, string or number

with 6 comments

huh, IE is one of those curses which came down to earth from the hell.
anyway if you face such problem you should check the following stuffs -

1. this guy described about the first problem
2. here is what i have faced and resolved,

i had a javascript code like this -

var element = new Element(“a”, {class: “keyboard_option_link”, href: “javascript: void(0)”});

so IE minds, because i have used “class” the fix i have used -

var element = new Element(“a”, {“class”: “keyboard_option_link”, href: “javascript: void(0)”});

this things now working fine,
best wishes,

Written by nhm tanveer hossain khan

May 25, 2008 at 11:14 pm

uncaught exception: Permission denied to get property Object.constructor

with 2 comments

seems you are getting “uncaught exception: Permission denied to get property Object.constructor” while you are  executing some javascript which was instantiating some objects and during that time it stucked with some exception.

for example

function get(pUpdate, pUrl, pParams) {
new Ajax.Updater(pUpdate, pUrl, {parameters: pParams});
}

if you want to regenerate this exception you can invoke this function with the following arguments -

get(“abc”, “http://abc”)

so why this crap ?

the main reason is in your code where you mentioned about “parameters” and which is not supposed to be null. you better write the following code -

function get(pUpdate, pUrl, pParams) {
var options = new Array();
if (pParams != null) {
options["parameters"] = pParams;
}

new Ajax.Updater(pUpdate, pUrl, options);
}
that will take away your javascript exception.

best wishes,

Written by nhm tanveer hossain khan

December 30, 2007 at 1:58 pm

Posted in javascript, tips

Google map: map.setCenter(latLng, zoomLevel)

with 2 comments

Recently i am playing with Google map. it is really fun. i am thinking i will share my experience through my blog.

problem: i want to set a center point
answer: you can use map.setCenter(new GLatLng(35.746512259918504,-42.1875), 2);
here 35.xxx is lat, -42.xx is lng  and 2 is zoom level.

how to use:

1. you can use “setCenter” when you instantiating an map object. for example:
var map = new GMap2(…);
map.setCenter(..);

2. you can use after completing your initial process. for example:
setCenter after loading marker from GDowloadUrl.

best of luck :)

Written by nhm tanveer hossain khan

April 12, 2007 at 12:12 pm

Customize HTML file field

without comments

Hi,

as we know html file field is unchangeable. you can change border style but you can’t use a button instead of traditional style.

recently i have introduced an article which clearly illustrated several examples.

though you can read it from here i am also giving my code snap.

here is live example: customized_file_field.html

<html>
<head>
<style type="text/css">
.file {
position: relative;
-moz-opacity:0;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
left: -160px;
}
.fake {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}
</style>

</head>
<body>
<form action="null" style="position: relative;">
<input type="file" name="file" class="file" id="upload-file" />
<div class="fake">
<input type="button" value="upload" />
<input type="submit" value="submit" />
</div>
</form>
</body>
</html>

Javascript: Delete child element with Effect.Fade (Effect.Fade and Element.remove)

with 2 comments

hi all,
let’s think you have a list of rows… when user click on delete button it sends a Ajax post request on server… after receiving JSON or XML response… it display a visual effect of destroying that row…
using Script.aculo.us you can make it with in a few seconds… new Effect.Fade(…) right!!!
but i think you DOM tree will not get that advantage as you are giving to your user… user could see visual disappearance of some object… but it is actually not deleting from DOM tree… you just hidding them… !!!

though you can use element.removeChid( childElement ) … but it is not much interactive approach as you want to show a visiual effect….

so here is my code snap… hope you will enjoy… and your visitor will happy as well as DOM tree will happy…

deleteElement: function(divId, options) {
try {
var element = $(divId);
var oldOpacity = element.getInlineOpacity();
var options = Object.extend({
from: element.getOpacity() || 1.0,
to:   0.0,
afterFinishInternal: function(effect) {
if(effect.options.to!=0) return;
var rootElement = $(BnChat.userListDiv);
rootElement.removeChild(effect.element);
effect.element.setStyle({opacity: oldOpacity});
}}, arguments[1] || {});
return new Effect.Opacity(element,options);
}
catch(e) {
// goes your exception handling
}
},

Written by nhm tanveer hossain khan

July 23, 2006 at 10:32 am

Posted in javascript