473,396 Members | 1,893 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,396 software developers and data experts.

How to give an ID value from tha directory name?

Hi everyone,
I'm super-newbie here... so thanx in advance for any help

I shoud give a "value" to an DIV's ID that change following the name of the
directory where the file is.

For example the file is here:
www.website.com/web/01/file.html

Is it possible with javascript to give the value "01" to the DIV's ID?
<div id="namedirectory"something inside </div>
so it could be readed as:
<div id="01"something inside </div>

I found in internet this one:

<script language="JavaScript">
fullpath=location.pathname;
document.write(fullpath);
document.write('<br />');
result=fullpath.split("\\");
document.write(result[5]);
</script>

it's something that could work?
I don't know how to recall the value in the ID...

Thanx a lot
Cheers,
Luca

Dec 21 '06 #1
6 1628
Daz

Luca wrote:
Hi everyone,
I'm super-newbie here... so thanx in advance for any help

I shoud give a "value" to an DIV's ID that change following the name of the
directory where the file is.

For example the file is here:
www.website.com/web/01/file.html

Is it possible with javascript to give the value "01" to the DIV's ID?
<div id="namedirectory"something inside </div>
so it could be readed as:
<div id="01"something inside </div>

I found in internet this one:

<script language="JavaScript">
fullpath=location.pathname;
document.write(fullpath);
document.write('<br />');
result=fullpath.split("\\");
document.write(result[5]);
</script>

it's something that could work?
I don't know how to recall the value in the ID...

Thanx a lot
Cheers,
Luca
Hi Luca.

If I understand what you want to do correctly, you should be able to do
this.

var div = document.getElementById('01');

div will now become a pointer to the dic element with th id of 01.

I would just like to point out, that as a rule of thumb, ALL ids should
start with a letter, and not a number.

'd1' would be an acceptable id name, whereas '1d' would not be as it
starts with a number. Also, ids need to be unique.

If you wanted to list all the div elements in the document, you can do
this with a while loop like so:

var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++)
{
// Do stuff with div her, perhaps alert it's name if it has one,
like so...
alert(divs[i].name);
}

If you want to dynamically change the id of the dive (not that you
should need to), you can do this:
var div = document.getElementById('01');
div.id = 'new_id';

Nice and easy. :)

I hope this helps and I haven't completely missed the question.

All the best.

Daz.

Dec 21 '06 #2
Daz

Luca wrote:
Hi everyone,
I'm super-newbie here... so thanx in advance for any help

I shoud give a "value" to an DIV's ID that change following the name of the
directory where the file is.

For example the file is here:
www.website.com/web/01/file.html

Is it possible with javascript to give the value "01" to the DIV's ID?
<div id="namedirectory"something inside </div>
so it could be readed as:
<div id="01"something inside </div>

I found in internet this one:

<script language="JavaScript">
fullpath=location.pathname;
document.write(fullpath);
document.write('<br />');
result=fullpath.split("\\");
document.write(result[5]);
</script>

it's something that could work?
I don't know how to recall the value in the ID...

Thanx a lot
Cheers,
Luca
Hi Luca.

If I understand what you want to do correctly, you should be able to do
this.

var div = document.getElementById('01');

div will now become a pointer to the div element with th id of 01.

I would just like to point out, that as a rule of thumb, ALL ids should
start with a letter, and not a number.

'd1' would be an acceptable id name, whereas '1d' would not be as it
starts with a number. Also, ids need to be unique.

If you wanted to list all the div elements in the document, you can do
this with a while loop like so:

var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++)
{
// Do stuff with div her, perhaps alert it's name if it has one,
like so...
alert(divs[i].name);

}

If you want to dynamically change the id of the dive (not that you
should need to), you can do this:
var div = document.getElementById('01');
div.id = 'new_id';

Nice and easy. :)

I hope this helps and I haven't completely missed the question.

All the best.

Daz.

Dec 21 '06 #3
Luca said the following on 12/21/2006 9:37 AM:
Hi everyone,
I'm super-newbie here... so thanx in advance for any help

I shoud give a "value" to an DIV's ID that change following the name of the
directory where the file is.

For example the file is here:
www.website.com/web/01/file.html

Is it possible with javascript to give the value "01" to the DIV's ID?
Yes, but, 01 is an illegal ID. ID'es can't begin with a number.
<div id="namedirectory"something inside </div>
so it could be readed as:
<div id="01"something inside </div>

I found in internet this one:

<script language="JavaScript">
fullpath=location.pathname;
document.write(fullpath);
document.write('<br />');
result=fullpath.split("\\");
document.write(result[5]);
document.write(result[result.length-2]);

will give you the folder name.

<script type="text/javascript">
fullpath=location.pathname;
result=fullpath.split("\/");
document.write('<div id="' + result[result.length-2] + '">);
</script>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '06 #4
Daz said the following on 12/21/2006 10:08 AM:

<snip>
If I understand what you want to do correctly, you should be able to do
this.

var div = document.getElementById('01');

div will now become a pointer to the div element with th id of 01.
He doesn't want a pointer, he wants to assign the id to it.

document.getElementById('someDiv').id = newID;
I would just like to point out, that as a rule of thumb, ALL ids should
start with a letter, and not a number.
That isn't a "rule of thumb" though, it is a rule of the specs that
ID'es can't begin with a number.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '06 #5
Thanx so much Daz & Randy... I've learned that 01 is an illegal ID name :)

well, my english is not the best so excuse me.

What I meant is easy to think but difficult to write :)

I want to change the ID value in a DIV. This value should be the same value
of the directory name where the file is allocated.

I try again with an example:

I have the file "example.html"
It is in a place in the web, for example the url is:
http://www.siteweb.com/directory/aboutus/example.html

so... in the htlm I have a DIV that inclused other stuff... for example:

<div id="JAVA">

some other code here

</div>
well... I need to change the value JAVA with the name of the subfolder
"aboutus" that is the name of the folder where example.html is

So if I will change the name of the subfolder in "contacts" the value JAVA
will be automatically changed.

Hope that's clear enough :)
Sooo sorry for my english

Luca
"Daz" <cu********@gmail.comha scritto nel messaggio
news:11*********************@a3g2000cwd.googlegrou ps.com...
If I understand what you want to do correctly, you should be able to do
this.

var div = document.getElementById('01');

div will now become a pointer to the div element with th id of 01.

I would just like to point out, that as a rule of thumb, ALL ids should
start with a letter, and not a number.

'd1' would be an acceptable id name, whereas '1d' would not be as it
starts with a number. Also, ids need to be unique.

If you wanted to list all the div elements in the document, you can do
this with a while loop like so:

var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++)
{
// Do stuff with div her, perhaps alert it's name if it has one,
like so...
alert(divs[i].name);

}

If you want to dynamically change the id of the dive (not that you
should need to), you can do this:
var div = document.getElementById('01');
div.id = 'new_id';

Nice and easy. :)

I hope this helps and I haven't completely missed the question.

All the best.

Daz.

Dec 21 '06 #6
Luca said the following on 12/21/2006 11:07 AM:
Thanx so much Daz & Randy... I've learned that 01 is an illegal ID name :)

well, my english is not the best so excuse me.

What I meant is easy to think but difficult to write :)

I want to change the ID value in a DIV. This value should be the same value
of the directory name where the file is allocated.
My first reply shows how to get the folder name. My reply to Daz shows
how to set the ID attribute after it has loaded.

fullpath=location.pathname;
result=fullpath.split("\/");
document.getElementById('JAVA').id = result[result.length-2];

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
3
by: Rainer Herbst | last post by:
Hi *, please help me solving the following problem: I have an XML document containing elements like <dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0" name="pressemitteilungen"...
0
by: Jack Wright | last post by:
Dear All, The following is the setting on IIS on a typical Client Server we are working on Authentication Methods Anonymous access (No user name/password required to access this resource.) ...
5
by: Bas Hendriks | last post by:
Has anyone any idea how asp.net find it's files back after compiling them to the temporary asp.net directory? I found on numerous webpages that the directorynames are chosen random but cannot find...
3
by: Saurabh | last post by:
Hi, my xml is: <ROOT> <FILE NAME="filename">CDATA</FILE> </ROOT> this xml is argument to a function in C#. i want to get the filename in a string variable. how do i do it???...
2
by: ELINTPimp | last post by:
Hello all, Have a really interesting problem (at least to me) with my upload_file() function. I have it working now, with a bit of a work around, but would like to know what everyone thinks in...
3
by: Charlotte | last post by:
Hello, info: I'me a rookie with IIS I have on a WinXP Pro the IIS installed, so I can test some pages before uploading to the hostserver online on the hostserver is a possibility (with the...
28
by: Peter Oliphant | last post by:
I have written a program using MS VS VC++ 2005 Express, /cli pure. Upon compiling it it works fine in the GUI development environment. It also works fine as a Debug stand-alone. ut I had an odd...
6
by: falconsx23 | last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.