473,382 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

id attribute of <body> tag

Claus Mygind
571 512MB
I want to dynamically add a hidden <div> </div> to a document when loading my page. It is kind of a generic scratch pad into which I can load messages and data I may want to display to the user. I want to do it this way so I can place it in my base .js file for inclusion in all apps I write without having to reinvent the wheel each time.

My problem is this; the <body> tag does not seem to pass the "id" value but rather the name of the application. I am using fireFox.

In this example the obj parameter becomes "appName.exe". And when I try to use the id in the function addScratchPad(obj) like this
var cThisApp = obj.id
I get an "undefined" error.

I want to use the id value to insert the scratchPad into the document like this
document.getElementById(cThisApp).innerHTML = "<div>.... other conten.. </div>

Here is my code:
Expand|Select|Wrap|Line Numbers
  1.  <HEAD>
  3. <TITLE> dailyTimeReview </TITLE>
  5.   <script type="text/javascript" language="JavaScript"    src="Navigation.js"></script>
  6. <script language="JavaScript">
  7. <!--])
  8.  function myStartUp(obj) 
  9.    {   
  10.           addScratchPad(obj);
  11.           aDepts = cMyDepts.split('~');
  12.    }  
  13. //-->
  14. </script>
  16. </HEAD>
  18. <body
  19.     id  ="testForm"
  20.     onLoad = "myStartUp(this);"
  21. >
function in the .js file

Expand|Select|Wrap|Line Numbers
  1. function addScratchPad(obj)
  2. {
  3. //this next line fails
  4. alert(obj.id);
  5. }
Jan 27 '09 #1
5 1795
8,658 Expert Mod 8TB
that's because "this" points to the window object (FireBug proved useful again).

to get the id I needed
Expand|Select|Wrap|Line Numbers
  1. function addScratchPad(obj)
  2. {
  3.     alert(obj.document.body.id);
  4. }
Jan 27 '09 #2
Claus Mygind
571 512MB
Hey that works great Dormilich. Thanks for the tip.
Jan 27 '09 #3
8,658 Expert Mod 8TB
if you're doing quite a lot of Javascript and HTML, FireBug will definitely help you (esp. the script runtime features, and the DOM view)
Jan 27 '09 #4
Claus Mygind
571 512MB
Thanks I already use it. I saw what you saw but just did not comprehend it.
Jan 27 '09 #5
8,658 Expert Mod 8TB
admittedly, fiddling through all the DOM data is a bit difficult.
Jan 27 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Andrés Giraldo | last post by:
Hi! It's possible to register some script between the <head> and </head> actually I'm Using RegisterStartupScript and RegisterClientBlockScript, but it works on the body By the way... how...
by: ryan.mclean | last post by:
Hello everyone. Hope ya'll had a nice New Year. Anyway, my question is why won't this work? I must be doing something dumb . . . here is the code: in the body tag, I have this code (just to...
by: francescomoi | last post by:
Hi. I'm trying to insert some text between <head> and <body> but I'm not able. I try with: -------- bodyPoint = document.getElementsByTagName('body'); var myLink =...
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
by: Chris Millar | last post by:
wondered if anyone could help me - i'm trying to control the value of an attribute of the BODY tag on a page. So i've got: <html> <body test="colin"> <form ...... ** content ** </form>...
by: WB | last post by:
Hi, How can I add an "onbeforeunload" event to the body tag of the MasterPage? All pages in my site follow a MasterPage and some of these pages require long processing. I'd like to show a...
by: Gustavo Arriola | last post by:
In ASP.NET 2.0: How I add an attribute to the tag <body>? From already thank you very much! Gustavo Arriola
by: Gustavo Arriola | last post by:
Hello! In ASP.NET 2.0: How I add an attribute to the tag <bodyin Codebehind? From already thank you very much! Gustavo Arriola
by: Xah | last post by:
Here's a interesting case of invalid html 4 strict file. In summary, if you have <body></bodywithout any content, the file would be invalid under html 4 strict. Valid if html 4 lose. <!DOCTYPE...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.