Need help about javascript

lnakuma

New Member
Messages
15
Reaction score
0
Points
0
Im fairly new to javascript.

I am trying to write a function that would create a div element inside the html without much of success.

here is my javascript function

Code:
function deleteBlogEntryLayer ( value, url ) {
  var msg;
  var msgcontent;
  if ( !document.getElementById('confirmDeleteBlog') ) {
    msg = document.createElement('div');
    msg.id = 'confirmDeleteBlog';
    msgcontent = document.createElement('div');
    msgcontent.id = 'confirmDeleteBlogContent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.className = "popLayer";
    msgcontent.className = "popLayerContent";
  } else {
    msg = document.getElementById('confirmDeleteBlog');
    msgcontent = document.getElementById('confirmDeleteBlogContent');
  }
  msgcontent.innerHTML = "<h1>Are you sure you want to delete this blog?</h1><br /><a href = \"javascript:void(0);\" onclick = \"deleteBlogEntry('"+ value +"')\" style = \"margin-right: 30px; font-size: 14px; color: #0000ff;\">Yes</a><a href = \"javascript:void(0);\" onclick = \"closeModalWindow('comfirmDeleteBlog');\" style = \"font-size: 14px; color: #0000ff;\">No</a>";
  openModalWindow('confirmDeleteBlog');
  msg.style.display = 'block';
  msg.focus();
}
css style poplayer and poplayerContent are in the mass css script file.
openModalWindow is a function that I know it works because I've used this function in other page.

Code:
function openModalWindow(value) {
  var div = $(value);
  var bgDiv = $('modalBackgroundDiv');

  var docDim = Element.getDimensions(document.body);
  //get the size of the window and calculate where the box should be placed
  var wDim = getBrowserWindowSize();
  var dDim = Element.getDimensions(div);
  // locate position of center window
  div.style.top = ((wDim.height - dDim.height*2) / 2) + 'px';
  div.style.left = ((wDim.width - dDim.width) / 2) + 'px';
  // set up background div, cover whole page instead of just the browser screen
  if (docDim.height > wDim.height) {
    wDim.height = docDim.height;
  }
  bgDiv.style.width = wDim.width + 'px';
  bgDiv.style.height = wDim.height + 'px';

  Element.show(div);
  Element.show(bgDiv);
}
function closeModalWindow(value) {
  Element.hide(value);
  Element.hide('modalBackgroundDiv');
}
function getBrowserWindowSize() {
  var winW = 630, winH = 460;
  // brower compatibility
  if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
      winW = window.innerWidth;
      winH = window.innerHeight;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
    }
  }
  var rval = {
    width: winW,
    height: winH
  };
  return rval;
}
and lastly, $('modalBackgroundDiv') is a div pre-defined in html

Code:
<div id = "modalBackgroundDiv" class = "modalPopupTransparent" style = "display: none;"></div>
I used a <a href onclick> to call deleteBlogEntryLayer function, only the pre-defined div layer modalBackgroundDiv poped up, and the div I created in javascript did not show at all.


Can someone point out what was wrong?

thx
 
Last edited:

taha116

Member
Messages
505
Reaction score
0
Points
16
sorry that i cant help you but here is a bump*

I see your fairly new to the forums so id like to make sure you understand this for your own benefit :
Dont be disappointed if you don't get help right away, there are allot of talented people on these forums. One of them is bound to read this and help out, just sit back and find something to kill time with, or work on something else you need to meanwhile.
 
Last edited:

lnakuma

New Member
Messages
15
Reaction score
0
Points
0
Thx for the advise.
I won't be disappointed if I did not get help right the way, and I'm sure I will be helped later some time when others have time either to sit down to read my post or to find problems of my code.

as far as your suggestion, that's what I am doing right now. put a javascript alert message at where my problem is, and move on to other part.

writing a brand new blog application takes time and I don't expect to finish it fast. :)


again, thanks for your help and concern.
 

vol7ron

New Member
Messages
434
Reaction score
0
Points
0
do you have a link to your page that you are testing?
 

lnakuma

New Member
Messages
15
Reaction score
0
Points
0

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Use Firebug (2) with Firefox, Safari 4's built-in debugger or Visual Web Developer Express with IE (Opera's dragonfly is still in development) to debug JS.

After viewing and clicking the links, the test page will log two errors in the browser's error console. For Safari:
Code:
ReferenceError: Can't find variable: $                                                                            ajax.js:3
TypeError: Result of expression 'Element.hide' [undefined] is not a function.                      ajax.js:24
Neither "$" nor "Element.hide" are defined as part of JS or the DOM. I'm guessing you're using Prototype, so you need to include prototype.js in the test page.
 
Last edited:

lnakuma

New Member
Messages
15
Reaction score
0
Points
0
I found out my problems.

first, msg.className should be 2 css classes instead of one.

and the other problem is simply a typo..

Code:
closeModalWindow('comfirmDeleteBlog');


who would spell confirm "comfirm"? jesus..... lol




btw: had firebug but never used it. now i see i should...
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
and the other problem is simply a typo..
It's amazing how many bugs are caused by typos. Even with modern IDEs' code colorers, auto-indentation, auto-completion and name checkers, they still happen. For instance, no IDE I know of could have caught your typo.

btw: had firebug but never used it. now i see i should...
Firebug is frickin' awesome.
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
@subasis: don't revive dead threads. This one is almost two years old.

Don't spam. I see all your posts are promotions for that website. You've been reported.
 

webpro2011

New Member
Messages
1
Reaction score
0
Points
0
@mission, first of all a thread which is not closed, can't be called a dead one. Secondly, I can show you many threads which include links to another particular website; even some of your moderators have done that. And you have not been reported for those. Links which have been posted by subasis here are indeed contain quality content which would be very useful for newbies. And last but not least, I can see that your forum is crowded with many a links of a particular website, and in so many cases not relevantly, which is a clear indication that there are people in this forum whose only concern is to promote that said website. So how can you allow another website to post links here? I can understand.
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
@mission, first of all a thread which is not closed, can't be called a dead one. Secondly, I can show you many threads which include links to another particular website; even some of your moderators have done that. And you have not been reported for those. Links which have been posted by subasis here are indeed contain quality content which would be very useful for newbies. And last but not least, I can see that your forum is crowded with many a links of a particular website, and in so many cases not relevantly, which is a clear indication that there are people in this forum whose only concern is to promote that said website. So how can you allow another website to post links here? I can understand.

The user in question had literally just searched "Firebug" and replied to all thread he could find with that link. While he could have got away with it at the time, bumping a thread which had already been resolved for the sole purpose of promoting their own website is somewhat different.

The thread most certainly was dead - it hadn't been posted in for two years.
 
Top