473,785 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change the ID dynamically

hello there.....
i have a problem here........... i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht

May 31 '06 #1
6 47685
ma***********@g mail.com wrote:
i have a problem here........... i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht


That is as impossible as your posting "style".

<URL:http://jibbering.com/faq/>
PointedEars
--
There are two possibilities: Either we are alone in the
universe or we are not. Both are equally terrifying.
-- Arthur C. Clarke
May 31 '06 #2
Thomas 'PointedEars' Lahn wrote:
ma***********@g mail.com wrote:
i have a problem here........... i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht


That is as impossible as your posting "style".


Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javas cript" type="text/javascript">
document.getEle mentsByTagName( 'p')[0].setAttribute(' id','myID');
alert(document. getElementById( 'myID').innerHT ML);
</script>
</body>
</html>

--
Bart

May 31 '06 #3
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
ma***********@g mail.com wrote:
> [assign ID attribute dynamically to the html tags]
That is as impossible as your posting "style".


Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javas cript" type="text/javascript">


The `language' attribute is deprecated long since, and your markup
is not Valid; especially, the missing DOCTYPE declaration triggers
Quirks Mode, which can change DOM behavior.
document.getEle mentsByTagName( 'p')[0].setAttribute(' id','myID');
alert(document. getElementById( 'myID').innerHT ML);
</script>
</body>
</html>


That is setting the attribute, not changing it. Note the Subject header.
Furthermore:

- This requires other DOM methods that may not be available.

- It is known to be not possible for some elements in some DOMs
(IIRC there are issues in the IE DOM).

- setAttribute() implementations are known to be buggy.
PointedEars
--
In the First World War, 13 million people were killed. In the Second
World War, 40 million people were killed. I think that if a third war
takes place, nothing is going to be left on the face of earth.
-- Shakira, 2003-02-05 @ MTV.com
May 31 '06 #4
Thomas 'PointedEars' Lahn said the following on 5/31/2006 8:26 AM:
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
ma***********@g mail.com wrote:
[assign ID attribute dynamically to the html tags]
That is as impossible as your posting "style". Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javas cript" type="text/javascript">


The `language' attribute is deprecated long since, and your markup
is not Valid;


Semi-valid point but irrelevant to the rebuttal to your assertion that
it was impossible.
especially, the missing DOCTYPE declaration triggers Quirks Mode,
which can change DOM behavior.
Only in IE and in this case it makes no difference.
document.getEle mentsByTagName( 'p')[0].setAttribute(' id','myID');
document.getEle mentById('p')[0].id = 'newID';
alert(document. getElementById( 'myID').innerHT ML);
</script>
</body>
</html>
That is setting the attribute, not changing it. Note the Subject header.


Yoohoo, dimwit, think about it. An element has an ID. You "set" the ID,
then alert that elements ID. It will give you the new ID. That is
changing the ID. You can be as pedantic as you want but the ID got changed.
Furthermore:

- This requires other DOM methods that may not be available.
Only if the user is using an antiquated anti-social browser.
- It is known to be not possible for some elements in some DOMs
(IIRC there are issues in the IE DOM).
Such as?
- setAttribute() implementations are known to be buggy.


Then you offer a better alternative. Or, preferably, you STFU and move on.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 31 '06 #5
Thomas 'PointedEars' Lahn wrote:
Bart Van der Donck wrote:
Thomas 'PointedEars' Lahn wrote:
ma***********@g mail.com wrote:
> [assign ID attribute dynamically to the html tags]

That is as impossible as your posting "style".


Why would that be impossible ?

<html>
<body>
<p>content</p>
<script language="javas cript" type="text/javascript">


The `language' attribute is deprecated long since, and your markup
is not Valid; especially, the missing DOCTYPE declaration triggers
Quirks Mode, which can change DOM behavior.
document.getEle mentsByTagName( 'p')[0].setAttribute(' id','myID');
alert(document. getElementById( 'myID').innerHT ML);
</script>
</body>
</html>


That is setting the attribute, not changing it. Note the Subject header.
Furthermore:

- This requires other DOM methods that may not be available.

- It is known to be not possible for some elements in some DOMs
(IIRC there are issues in the IE DOM).

- setAttribute() implementations are known to be buggy.


Hmmmm, that Asperger-smell in the morning :-)

--
Bart

May 31 '06 #6
You can assign an id to any element simply by saying:

El.id = "foo";

If, for instance, you wanted to assign an ID to every FORM tag on the
page, you could do:

for(var i=0; i<document.form s.length; i++) {
document.forms[i].id = "formtag_" + i;
}

If you had three FORM tags on your page and you ran that loop, the form
tags would have ids "formtag_0" , "formtag_1" , "formtag_2" .

Exactly how you will iterate over the tags you want to assign IDs to
will depend on exactly which tags you need to work with.

ma***********@g mail.com wrote:
hello there.....
i have a problem here........... i want to assign ID attribute
dynamically to the html tags......and i need a function for tht....can
anybody help me out in tht


Jun 1 '06 #7

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

Similar topics

7
2933
by: juglesh | last post by:
Hello, I would like to be able to have the user sort a list of items similarly to the way you sort your queue on Netflix.com. (the numbers dont change dynamically on netflix, they must be doing something serverside with them) Like this: ( represents a text or select filed) an item something else a differnt thing the other
2
1754
by: puunda | last post by:
Hi All, I had previously asked this question with regard to Cyrstal Reports, which I believe is not the most suitable for doing the job. The problem: I need to create a report with X number of items (statistics), and Y number of graphs/charts. The report will be viewed on screen, printed, or saved as pdf. The report is created as you would a report. The user
3
2487
by: jpatterson | last post by:
Hi, I need to be pointed in the right direction. I'm looking for a way to dynamically change a table in a query. I have a table called students and each fiscal year the student table will get rolled to a new table student2004. Currently all the reports are based on queries using the student table. I would like to give the user the option to pick a report and then pick the fiscal i.e. 2004 and then have the query table change...
3
5734
by: Quentin | last post by:
Hey there ! I made my own WebControl, that inherits from WebControls, and i added an HtmlTable to it. I would like to include a file, dynamically, to one of its cells... I've already searched, and found HttpContext.Current.Server.Execute("mapage.aspx") but it executes the page where i call it, and not in the cell... i also tried something like that : MyTable.Rows(0).Cell(0).InnerHtml = Server.Execute("MaPage.aspx") but it doesn't...
37
8970
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use). I then change dynamically the connection string by doing : My.Settings.Item("ConnectionString") = "some connection sring" The problem is that if another user loggs in and chooses another client, then obviously it changes the connection string...
3
3682
by: DMA | last post by:
Hello, How can I change my IP address ? I try to do it in C#. It's easy to get the IP but to fix it is another problem.. Sincerely David M.
5
8590
by: marfi95 | last post by:
I have a form that has a left and right panel. In the left panel is a treeview. The right panel I want to change dynamically based on the type of node selected. What I'm doing is loading the treeview nodes through an XML file. As part of each node in the XML, I'm using an attribute that indicates the name of a sub form to load. As part of all these little child forms, the main control is a panel, which I then assign its parent to the...
1
3008
by: difah | last post by:
Hello, I'am currently designing a reportviewer, and what i want to do is when the user click on a image, this image change. I know how to change dynamically the image on load but not on click. Thanks for your help.
2
1305
missshaikh
by: missshaikh | last post by:
hi friends I am programming a website which will include ad banners. The requirements are that the banners will be dynamically changing for each page. By this I mean that if there are ten banners in total and each page will always have two banners. So that two of the ten banners will be randomly selected and placed in the webpage. I have this part figured out. the problem I am facing is that they want to have the ability that banner...
0
1163
by: panindra | last post by:
hi im newbie to flex.. im using itemrenderer in a list to use a Hbox.. n Hbox contains a image,label and button,...i v to change a particular row of a list... To be more precise,i v to change the image of particular row of a list dynamically. how ca i change dynamically the source of that image? please anyone help me..
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.