Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2006, 04:11 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default DOM functionality. Urgent

Hallo to all,

I am pretty new to the DOM functionalities of Javascript. I have designed a test code like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript" language="javascript">
function start() {
        var mybody = document.getElementsByTagName("body")[0];
        myPa = document.getElementsByTagName("p");
        myBodyElements = document.createElement("p");
        currenttext = document.createTextNode("Hallo world");
        myBodyElements.appendChild(currenttext);
        myP = myPa[1];
        myP.style.background = "rgb(255,0,0)";
        mybody.appendChild(myBodyElements);
        mybody.appendChild(myBodyElements);


}
</script>
</head>

<body onload="start()">

<p>Test</p>
<p>Test2</p>
<h3>Test3</h3>
<h2>Test4</h2>
</body>
</html>

So what I also wanted to do is to write a function which prints out:

myPa is Test2. How can I manage to do it?

Another question:

I am having a document which has anchors but my boss first wants to see these links as plain text. What should I do?

Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old July 6th, 2006, 04:40 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Nearly all questions are urgent to the sender, please take a step back and define the problem more clearly.

What exactly do you need for the function, for example:
Code:
function writeRubbish()
{
  var oDiv = document.createElement("div");
  oDiv.innerHTML = "myPa is Test2";
  document.body.appendChild(oDiv);
}
writes what you want.

For the second question what exactly does he want to see, the links but not working or the target URL or something else? Does he want a list separate to the page or on the page?

--

Joe (Microsoft MVP - XML)
 
Old July 6th, 2006, 04:58 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallo Joe,


For the first question I just wanted to write a codeline which gets the Element content (here is the p[1]= Test2 and to write it again to make sure if I am taking the element value. If I write

document.writeln("myP is"+myP);

Then I see the result as

myP is [object]. It only references it as an object and writes its property.

Second Question:
what he wants to have from me is to see
<td width="100%" align="left" valign="middle"><input type="hidden" name="FRARUN0020060704e2750001p_adoctoc" value=""><A class="hl" ID="FRARUN0020060704e2750001p" title="" href="../gen/article.asp?med=&amp;AN=FRARUN0020060704e2750001p" onClick="articleClicked('FRARUN0020060704e2750001p ','External news','frarun','','','','','-1','T|article N|fmt O|c T|report N|fmt O|c O|, T|file N|fmt O|c O|, T|webpage N|fmt O|c O|, T|patentamt U| O|t T|patent U|3 O|t O|, T|alain T|pompidou O|. O|, T|de N|la O|c T|patente T|frau O|. T|patenter T|mann O|. O|, T|patent T|und O|. T|rechtsanwaltskanzlei O|. O|, T|tprw N|rst O|c O|, T|dundf N|rst O|c O|, T|shabd N|rst O|c O|, T|gent N|ns O|c O|, T|gspo N|ns O|c O|, T|c01 N|ns O|c O|, T|c15 N|ns O|c O|, T|c151 N|ns O|c O|, T|npeo N|ns O|c O|, T|mcat N|ns O|c O|, T|c18 N|ns O|c O|, T|c42 N|ns O|c O|, O|- O|+ T|intellectual T|property O|. T|propriété T|intellectuelle O|. O|, T|geistiges T|eigentum O|. O|, T|cgymtr N|ns O|c O|+ T|de N|la O|c T|en N|la O|c O|, T|fr N|la O|c O|, O|+ O|, T|stammzelle U|1 O|t T|stemm T|cell U|1 O|t O|. O|, T|cellule U|5 O|t T|souche U|5 O|t O|. O|, T|europaeische T|union O|. T|eu O|, T|european T|union O|. O|, T|foerderung O|, T|government U| O|t T|aid U|1 O|t O|. O|, T|patentierbarkeit O|, T|patentab U|5 O|t O|, O|+ T|de N|la O|c T|en N|la O|c O|, T|fr N|la O|c O|, O|+ O|, T|office T|européen O|. T|des O|. T|brevets O|. T|brevet U|5 O|t O|, T|alain T|pompidou O|. O|, T|brevet T|d O|. T|etat O|. T|brevet T|des O|. T|collèges O|. O|, T|brevet T|de O|. T|la O|. T|sécurité O|. O|, T|brevet T|de O|. T|technicien O|. O|, T|brevet T|d O|. T|enseignement O|. T|commercial O|. O|, T|brevet T|de O|. T|recherche O|. T|utilitaire O|. O|, T|brevet T|de O|. T|pilote O|. O|, T|brevet T|d O|. T|initiation O|. T|aéronautique O|. O|, T|brevet T|métier O|. T|d O|. T|art O|. T|armurerie O|. O|, T|brevet T|de O|. T|collèges O|. O|, T|brevets T|de O|. T|la O|. T|préparation O|. T|militaire O|. O|, T|brevet T|de O|. T|respectabilité O|. O|, T|brevet T|professionnel O|. O|, T|brevets T|blancs O|. O|, T|diplôme T|national O|. T|du O|. T|brevet O|. O|, T|brevet T|agricole O|. O|, T|brevetées T|uniques O|. O|, T|brevets T|de O|. T|nationalisme O|. O|, T|brevet T|de O|. T|capitaine O|. O|, T|brevet T|de O|. T|maîtrise O|. O|, T|brevets T|d O|. T|états O|. O|, T|breveté T|officier O|. O|, T|brevet T|d O|. T|avocat O|. O|, T|brevet T|informatique O|. O|, T|brevet T|fédéral O|. O|, T|brevet T|de O|. T|recherche O|. T|utilitaire O|. O|, T|brevet T|pour O|. T|l O|. T|exercice O|. O|, T|brevet T|sportif O|. O|, T|brevet T|de O|. T|montagne O|. O|, T|brevet T|de O|. T|base O|. O|, T|brevet T|de O|. T|sécurité O|. T|routière O|. O|, T|brevetés T|pour O|. T|les O|. T|voyages O|. O|, T|brevet T|de O|. T|secourisme O|. O|, T|passage T|du O|. T|brevet O|. O|, T|l T|examen O|. T|du O|. T|brevet O|. O|, T|brevet T|de O|. T|patron O|. O|, T|tprw N|rst O|c O|, T|shabf N|rst O|c O|, T|gent N|ns O|c O|, T|gspo N|ns O|c O|, T|c01 N|ns O|c O|, T|c15 N|ns O|c O|, T|c151 N|ns O|c O|, T|npeo N|ns O|c O|, T|mcat N|ns O|c O|, T|c18 N|ns O|c O|, T|c42 N|ns O|c O|, T|gedu N|ns O|c T|glife N|ns O|c O|- O|, T|gfire N|ns O|c O|, T|gtour N|ns O|c O|, T|gdis N|ns O|c O|, O|- T|fr N|la O|c O|+ O|, T|european T|patent O|. T|office O|. T|patent U|1 O|t O|, T|alain T|pompidou O|. O|, T|mcat N|ns O|c T|c1522 O|, T|update U|5 O|t O|, T|share U|5 O|t O|, T|stock U|5 O|t O|, T|tprw N|rst O|c O|, T|dundf N|rst O|c O|, T|shabd N|rst O|c O|, T|bwr N|rst O|c O|, T|indfed N|rst O|c O|, T|gent N|ns O|c O|, T|gspo N|ns O|c O|, T|c01 N|ns O|c O|, T|c15 N|ns O|c O|, T|c151 N|ns O|c O|, T|npeo N|ns O|c O|, T|c18 N|ns O|c O|, T|c42 N|ns O|c O|, T|gcat N|ns O|c O|, O|- T|en N|la O|c O|+ O|, T|octrooibureau O|, T|nrgn N|ns O|c T|nrmf N|ns O|c O|, T|nnam N|ns O|c O|, O|- O|+','11069554'); return false;">Der Bikini - **************** mit 60</A>&nbsp;&nbsp;&nbsp;<span class="source">Frankfurter Rundschau, 5 July 2006, 697 words, German</span></td>

as
<p>Der Bikini - **************** mit 60&nbsp;&nbsp;&nbsp;<span class="source">Frankfurter Rundschau, 5 July 2006, 697 words, German</span></p>

And what I am trying to do is to build a DOM structure to do that



Your attitude determines your altitude
 
Old July 6th, 2006, 05:27 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

For the first part write:
Code:
document.writeln("myP is: " + myP.outerHTML);
but you won't see it properly as the HTML will be interpreted, maybe better for debugging to use alert:
Code:
alert("myP is: " + myP.outerHTML);
I'm sorry but I've no idea about the second part at the moment, I'll need to spend time deciphering what's going on.

--

Joe (Microsoft MVP - XML)
 
Old July 6th, 2006, 05:30 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thanks a lot. If you can find a solution for the second part please let me know from here

Your attitude determines your altitude
 
Old July 16th, 2006, 10:20 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Hi,

Heres the new code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script type="text/javascript" language="javascript"> function start() {
        var mybody = document.getElementsByTagName("body")[0];
        myPa = document.getElementsByTagName("p");
        myBodyElements = document.createElement("p");
        currenttext = document.createTextNode("Hallo world");
        myBodyElements.appendChild(currenttext);
        myP = myPa[1];
        myP.style.background = "rgb(255,0,0)";
        mybody.appendChild(myBodyElements);
        mybody.appendChild(myBodyElements);
        document.write('myPa is ' + myPa);


}
</script>
</head>

<body onload="start();"> //Take note the bold colon, you didnt have that and its essential for the code to work!

<p>Test</p>
<p>Test2</p>
<h3>Test3</h3>
<h2>Test4</h2>
</body>
</html>


 
Old July 16th, 2006, 04:12 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You don't need the bold semicolon.

Jon Emerson
http://www.digg.com/users/panaceaa/profile





Similar Threads
Thread Thread Starter Forum Replies Last Post
add functionality SKhna Javascript 0 February 5th, 2008 08:34 AM
GSM Functionality taofeeklasisi Pro Visual Basic 2005 0 September 18th, 2007 07:01 AM
PHP Web-browser DOM functionality Philibuster Beginning PHP 1 August 15th, 2006 09:34 PM
Functionality of dataadaptor haribala.raj General .NET 1 September 13th, 2005 01:01 PM
Functionality in Dotnet anand_asv General .NET 1 April 8th, 2005 02:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.